Last active
February 17, 2017 17:37
-
-
Save sminutoli/d2f25bab76f942ff458bbd3d7439b317 to your computer and use it in GitHub Desktop.
Ejemplos para DPTC#15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); // {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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