Stancobridge Posted May 5, 2016 Share Posted May 5, 2016 Hello everyone, am new here and I believe that am going to get more help in this wonderful community... Since am a beginner in web programming. I started with Javascript, on learning it I got stucked in String. Where we have Constructor, Prototype and Length. I understood others but am still getting confused on Prototype. I didn't understand really what they are trying to teach. I know it is used to add a new value to an object. But the question is how? How can we use the added value? Where can we use it. Please I need help on this..am waiting in anticipation. Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted May 5, 2016 Share Posted May 5, 2016 If you add a property or method to the prototype of any object then it becomes available on every instance of that object. e.g.: String.prototype.showLength = function() { return this.toString() + " - length " + this.length; } var test = new String('some string'); console.log(test.showLength()); Link to comment Share on other sites More sharing options...
Stancobridge Posted May 6, 2016 Author Share Posted May 6, 2016 thanks bro...but I need more light on this Link to comment Share on other sites More sharing options...
Ingolme Posted May 6, 2016 Share Posted May 6, 2016 What part are you having trouble understanding? There is nothing more to it than what was explained. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now