Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

promises and not callbacks

var Button = function(content) {   this.content = content;};Button.prototype.click = function() {  console.log(this.content + ' clicked');}var myButton = new Button('OK');myButton.click();var looseClick = myButton.click;looseClick(); // not bound, 'this' is not myButton - it is the global objectvar boundClick = myButton.click.bind(myButton);boundClick(); // bound, 'this' is myButton
Source by medium.com #
 
PREVIOUS NEXT
Tagged: #promises #callbacks
ADD COMMENT
Topic
Name
5+8 =