Let's say I have a object from a class that contains methods and properties like so:
function Fruit (type, color) {
this.type = type;
this.color = color;
this.getInfo = function() {
return this.color + ' ' + this.type;
};
this.loadJSON = function() {
//TODO
};
}
var red_apple = new Fruit ('apple', 'red');
I want to load new data from JSON like:
red_apple.loadJSON( '{"new_apple": {"color": "green", "type": "apple"}}' );
How would I implement this.loadJSON
? Is there a standard function?