Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

prototype chain in javascript

var o = {
  a: 2,
  m: function() {
    return this.a + 1;
  }
};

console.log(o.m()); // 3
// When calling o.m in this case, 'this' refers to o

var p = Object.create(o);
// p is an object that inherits from o

p.a = 4; // creates a property 'a' on p
console.log(p.m()); // 5
// when p.m is called, 'this' refers to p.
// So when p inherits the function m of o, 
// 'this.a' means p.a, the property 'a' of p


Comment

chaining prototype methods

function Shape(){//from  ww  w.j a  v a  2  s .  co  m
   this.isDrawable = true;
}
Shape.prototype.getDrawable = function(){
   return this.isDrawable;
};

function Rectangle(){
   this.hasFourEdges = false;
}

//inherit from Shape
Rectangle.prototype = new Shape();

Rectangle.prototype.getFourEdges = function (){
   return this.hasFourEdges;
};

var instance = new Rectangle();
console.log(instance.getDrawable());   //true
Comment

prototype chain in javascript

{
    prop: "some value",
    __proto__: {
        foo: "bar",
        constructor: ƒ doSomething(),
        __proto__: {
            constructor: ƒ Object(),
            hasOwnProperty: ƒ hasOwnProperty(),
            isPrototypeOf: ƒ isPrototypeOf(),
            propertyIsEnumerable: ƒ propertyIsEnumerable(),
            toLocaleString: ƒ toLocaleString(),
            toString: ƒ toString(),
            valueOf: ƒ valueOf()
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript save as pdf 
Javascript :: how ot send user agent in nodejs https header 
Javascript :: why my favicon icon is not removing in react 
Javascript :: nodejs get cpu count 
Javascript :: sintax arrow function in javascript 
Javascript :: check property exists in object javascript 
Javascript :: angular $http abort request 
Javascript :: jsonplaceholder typicode 
Javascript :: JavaScript Extract Values 
Javascript :: jQuery - Remove 
Javascript :: use of length property 
Javascript :: vue js set array value by key 
Javascript :: check variable value and do something 
Javascript :: redux-logger 
Javascript :: esql convert blob to json 
Javascript :: react native measure 
Javascript :: jQuery exists function 
Javascript :: multiple elements with same id jquery 
Javascript :: dropdown hide 
Javascript :: react native skeleton 
Javascript :: angular 8 features 
Javascript :: hashnode 
Javascript :: declaring two variables inside for loop 
Javascript :: create random password 
Javascript :: how to add icon in javascript 
Javascript :: js spread parameters 
Javascript :: stringy 
Javascript :: mongoose populate array of ids 
Javascript :: how to use brand icons in react 
Javascript :: javascript string literal 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =