+ 1
Prototype
What are prototype in js... Can someone explain with examples
3 ответов
+ 2
A prototype is (exactly the prototype of objects) the basic set of methods and properties of an object.
An Arrays prototype method split() can be called by any variable of type String.
var str = new String("test");
var arr = str.split('e');
A variable of type string inherits every property and method from It's type.
String.prototype.split -> str.split
0
Coding Agent
So like i have something like this
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
This is an Object constructor
So the Person inherits the methods and propertys from Person.prototype that itself inherits from Object.prototype
Yeah?
0
Yes, then you create an object with
var myPerson = new Person(params);
And it inherits the properties of Person.