Created
May 26, 2017 00:02
-
-
Save anthonybrown/eba9758d8fabec7c7cfb7d0ddb9d43b7 to your computer and use it in GitHub Desktop.
JS Bin JavaScript Implicit Binding // source https://jsbin.com/teguta
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="JavaScript Implicit Binding"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
/* Implicit Binding */ | |
/* Left of the dot at call time. */ | |
var Person = function(name,age) { | |
return { | |
name: name, | |
age: age, | |
sayName: function () { | |
console.log(this.name); | |
}, | |
mother: { | |
name: 'Patty', | |
sayName: function() { | |
console.log(this.name); | |
} | |
} | |
}; | |
}; | |
var tony = new Person('Tony', 50); | |
tony.sayName(); | |
tony.mother.sayName(); | |
// var sayNameMixin = function (obj) { | |
// obj.sayName = function() { | |
// console.log(this.name); | |
// }; | |
// }; | |
// var me = { | |
// name: 'Tony Brown', | |
// age: 50 | |
// }; | |
// var you = { | |
// name: 'Joey', | |
// age: 45 | |
// }; | |
// sayNameMixin(me); | |
// sayNameMixin(you); | |
// me.sayName(); | |
// you.sayName(); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/* Implicit Binding */ | |
/* Left of the dot at call time. */ | |
var Person = function(name,age) { | |
return { | |
name: name, | |
age: age, | |
sayName: function () { | |
console.log(this.name); | |
}, | |
mother: { | |
name: 'Patty', | |
sayName: function() { | |
console.log(this.name); | |
} | |
} | |
}; | |
}; | |
var tony = new Person('Tony', 50); | |
tony.sayName(); | |
tony.mother.sayName(); | |
// var sayNameMixin = function (obj) { | |
// obj.sayName = function() { | |
// console.log(this.name); | |
// }; | |
// }; | |
// var me = { | |
// name: 'Tony Brown', | |
// age: 50 | |
// }; | |
// var you = { | |
// name: 'Joey', | |
// age: 45 | |
// }; | |
// sayNameMixin(me); | |
// sayNameMixin(you); | |
// me.sayName(); | |
// you.sayName();</script></body> | |
</html> |
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
/* Implicit Binding */ | |
/* Left of the dot at call time. */ | |
var Person = function(name,age) { | |
return { | |
name: name, | |
age: age, | |
sayName: function () { | |
console.log(this.name); | |
}, | |
mother: { | |
name: 'Patty', | |
sayName: function() { | |
console.log(this.name); | |
} | |
} | |
}; | |
}; | |
var tony = new Person('Tony', 50); | |
tony.sayName(); | |
tony.mother.sayName(); | |
// var sayNameMixin = function (obj) { | |
// obj.sayName = function() { | |
// console.log(this.name); | |
// }; | |
// }; | |
// var me = { | |
// name: 'Tony Brown', | |
// age: 50 | |
// }; | |
// var you = { | |
// name: 'Joey', | |
// age: 45 | |
// }; | |
// sayNameMixin(me); | |
// sayNameMixin(you); | |
// me.sayName(); | |
// you.sayName(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment