/ Published in: JavaScript

Shows you how to link 2 objects together via the object function. If a value isn't found in the object, it will look for it in the linked object.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//used below in "secret" linking function object(o){//new function, argument o function F() {}//define function F(empty) F.prototype = o;//add the custom property/method passed through o return new F();//return the new function with the added property/method } //Old object var myObject = { name: "Matt", dob: "12/12/1913", age: "95", ocupation: "Web Developer" } //Secret link new object to old object var myNewObject = object(myObject); //add values to the new object myNewObject.name = "new name"; myNewObject.crime = "crime"; //it can't find "age" in new object, it looks at the old object via the link. console.info(myNewObject.crime);//firebug console.info(myNewObject.age);//firebug //delete info in an object delete myObject.ocupation; console.warn(myObject.ocupation);//firebug
Comments
