Prototype Chain Sample

by andypotanin

JavaScript

function Model( name ) {
    this.name = name;
}

Model.o1 = function o1() {}
Model.o2 = function o2() {}

Model.prototype.p1 = function p1() {}
Model.prototype.p2 = function p2() {}

var Instance0 = Object.create( Model );
var Instance2 = Object.create( Model.prototype );
var Instance3 = Object.create( Model ).__proto__; Instance3.__proto__ = Object.create( Model.prototype ).__proto__;

Model.o3 = function o3() {}
Model.prototype.p3 = function p3() {}

console.log( 'function' === typeof Instance3.o1 );
console.log( 'function' === typeof Instance3.o2 );
console.log( 'function' === typeof Instance3.o3 );
console.log( 'function' === typeof Instance3.p1 );
console.log( 'function' === typeof Instance3.p2 );
console.log( 'function' === typeof Instance3.p3 );