• Like
  • Save
Prototype & Inheritance in JavaScript
Upcoming SlideShare
Loading in...5
×
 

Prototype & Inheritance in JavaScript

on

  • 940 views

What is prototype and how we use it to inherit the properties of an object in JavaScript.

What is prototype and how we use it to inherit the properties of an object in JavaScript.

Statistics

Views

Total Views
940
Views on SlideShare
938
Embed Views
2

Actions

Likes
1
Downloads
20
Comments
0

1 Embed 2

http://192.168.6.179 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Prototype & Inheritance in JavaScript Prototype & Inheritance in JavaScript Presentation Transcript

    • Prototype & Inheritance in JavaScript C# Corner – 21st September Sunny Kumar
    • 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.
    • 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.
    • 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"
    • • prototype is a property of function object. • Only function Objects can have prototype property.
    • var foo = function(){}; console.log(foo.prototype); Object {} //output
    • 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 !”
    • foo.prototype={x:1,y:2}
    • var Person = function(name) { this.name = name; }; Person.prototype.say = function(){ return this.name; };
    • var dude = new Person('dude'); dude.name; // "dude“ dude.say(); // "dude“ same result