Add methods to object example.
by wilt
JavaScript
var object = {
name: "object name",
description: "object description",
properties: [
{ name: "first", value: "1" },
{ name: "second", value: "2" },
{ name: "third", value: "3" }
]
};
SmartObject = function( object ){
this.name = object.name;
this.description = object.description;
this.properties = object.properties;
};
SmartObject.prototype.getName = function(){
return this.name;
};
SmartObject.prototype.getDescription = function(){
return this.description;
};
SmartObject.prototype.getProperies = function(){
return this.properties;
};
var smartObject = new SmartObject( object );
console.log( smartObject );
object.__proto__ = SmartObject.prototype;
console.log( object );