2. Prototypes in JavaScript
• What is Prototype?
• Augmenting the Prototype
• Overwriting the Prototype
• Use of Prototype
• Prototype Chain
Inheritance in JavaScript
• Various ways of Inheritance in JavaScript.
3. Sneak Peek into past…
Functions
- are objects.
- returns Value.
- can return objects, including other functions.
- they have properties.
- they have methods.
- can be copied, deleted, augmented.
- special feature: Invokable.
- when invoked with new keyword, returns an object named
this , can be modified before it’s returned.
4. Sneak Peek into past…
Constructor Functions
var Person = function(name) {
this.name = name;
this.getName = function() {
return this.name;
};
};
var me = new Person(“Sunny");
me.getName(); // “Sunny"
5.
6.
7. • prototype is a property of function object.
• Only function Objects can have prototype property.
8. var foo = function(){};
console.log(foo.prototype);
Object {} //output
9. Var foo=function(){};
Var myFoo = new foo(); //instantiates an object of foo.
foo.prototype.MaxValue=100;
foo.prototype.SayHello=function(name){
return “Hi “+name+” !”;
}
myFoo.SayHello(“Kumar”); // “Hi Kumar !”