Hi Friends,
I thought it would be nice to share some cool, good Java-script coding Practice. Recently, I attended one of my friend’s Native-Script conference (For more info around Native Script, read here http://nativescript.org/). There I found, people struggling with new kind of JavaScript syntax. I would recommend all web developers, prospective full stack developers, graduates, anyone, wherever writing any form of JavaScript code, make prototyping style in your DNA.
Let me give few examples around it. Below is the sample HTML and script. Code is very simple and self explanatory. However, to make it more clear, I have also put comments around the same. Also, while writing the same, you can see below screenshot, editor is helping at every point. I am using webstorm here. You can use any of your favorite editors.
Below is the finished snippet of the same.
With the above change in place, when i simply go ahead and test the same in browser, it will give me below output.
Till this point, we have not seen prototyping, this is just a simple example around class in javascript. Now, Lets go ahead and extend the existing function with the help of prototyping. Below is the finished snippet for the same. As you can see that for adding any functionality to existing class or function in terms of JavaScript, we need to make use of prototype keyword.
With the above change in place, when I run this functionality, then this will give new improvised output.
I hope, you would have liked the first part of Prototyping with JavaScript. Will see some more examples in coming section. Till then stay tuned and Happy Cooding.
Thanks,
Rahul Sahay
Happyy Coding
Awesome Example
Thanks:)
Very short and simple example and explanation.
This is just the 1st part. Others will be available shortly!