I have a prototype model where I need to include the following extension methods into the prototype:
String.prototype.startsWith = function(str){
return (this.indexOf(str) === 0);
}
Example: [JS]
sample = function() {
this.i;
}
sample.prototype = {
get_data: function() {
return this.i;
}
}
In the prototype model, how can I use the extension methods or any other way to create extension methods in JS prototype model.
Calling the new method on string:
should be as simple as:
For your second example, I assume you want a constructor that sets the member variable "i":
You can use this as follows: