Skip to content

Instantly share code, notes, and snippets.

@sminutoli
Last active February 17, 2017 17:37
Show Gist options
  • Save sminutoli/d2f25bab76f942ff458bbd3d7439b317 to your computer and use it in GitHub Desktop.
Save sminutoli/d2f25bab76f942ff458bbd3d7439b317 to your computer and use it in GitHub Desktop.
Ejemplos para DPTC#15
// ES5
var Item = {
quality: 0,
sellIn: 10,
update: function fnUpdate(){
this.updateQuality();
this.updateSellIn();
if(recursion) return fnUpdate.call(this); // esto no depende de la propiedad update del objeto
},
updateQuality: function fnUpdateQuality(){
this.quality++;
},
updateSellIn: function fnUpdateSellIn(){
this.sellIn--;
}
};
console.log(Item.update.prototype); // {}
new Item.update(); // {}
// ES2015
var Item = {
quality: 0,
sellIn: 10,
update(){
this.updateQuality();
this.updateSellIn();
if(recursion) return this.update(); // si llega a cambiar la propiedad update del objeto, esto no funciona
},
updateQuality(){
this.quality++;
},
updateSellIn(){
this.sellIn--;
}
};
console.log(Item.update.prototype); // undefined
new Item.update(); // TypeError update is not a constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment