/*
*******************************************************
ZAKAS OOP CHAPTER FOUR : constructors / prototypes
*******************************************************
*/
/*
**********************************************************
prototypes ... PROTOTYPE OBJECTS is where the fun is at
--they are recipes for objects and each instance keeps
track of it's origin using [[PROTOTYPE]] internal
**********************************************************
*/
//when using object prototype methods, JS will look for
//the matching method on the instance, if not there, it
//will move up to the next objeect in the prototype chain,
//if not there, it will keep going until it finds it
var genericObject = {};
//Object.toString used
console.log(genericObject.toString());
//we want better info about the INSTANCE, so
//overwrite default toString with ownProperty method
//with same name
genericObject.toString=function(){
return '[object GenericObject]';
};
//run toString on genericObject
console.log(genericObject.toString());
//now remove it to use Object Prototype again
delete genericObject.toString;
//Object.toString used again
console.log(genericObject.toString());
/*
// For any generic object, [[Prototype]] is always a reference
// to Object.prototype.
var object = {};
var prototype = Object.getPrototypeOf(object);
//true
console.log(prototype === Object.prototype);
// TEST to see if one object is a prototype for
// another by using the isPrototypeOf() method:
var object = {};
//true
console.log(Object.prototype.isPrototypeOf(object));
//******************************************************************************************
// An INSTANCE keeps track of its prototype through an internal
//property called [[Prototype]]. This property is a pointer back
//to the prototype object that the instance is using. When you create
//a new object using ~~~ new ~~~, the constructor’s prototype
//property is assigned to the [[Prototype]] property of that new...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.