Skip to content

Instantly share code, notes, and snippets.

@sumitramteke
Forked from anonymous/index.html
Last active February 22, 2016 05:02
Show Gist options
  • Save sumitramteke/079e42645b4068086f76 to your computer and use it in GitHub Desktop.
Save sumitramteke/079e42645b4068086f76 to your computer and use it in GitHub Desktop.
var Person = function(firstName) {
this.firstName = firstName;
};
Person.prototype.sayHello = function() {
console.log("Hello, I'm " + this.firstName);
};
var person1 = new Person("Alice");
var person2 = new Person("Bob");
var helloFunction = person1.sayHello;
person1.sayHello();
person2.sayHello();
helloFunction();
console.log(helloFunction === person1.sayHello);
console.log(helloFunction === Person.prototype.sayHello);
helloFunction.call(person1);
<html></html>
<script id="jsbin-javascript">
var Person = function(firstName) {
this.firstName = firstName;
};
Person.prototype.sayHello = function() {
console.log("Hello, I'm " + this.firstName);
};
var person1 = new Person("Alice");
var person2 = new Person("Bob");
var helloFunction = person1.sayHello;
person1.sayHello();
person2.sayHello();
helloFunction();
console.log(helloFunction === person1.sayHello);
console.log(helloFunction === Person.prototype.sayHello);
helloFunction.call(person1);
</script>
<script id="jsbin-source-javascript" type="text/javascript">var Person = function(firstName) {
this.firstName = firstName;
};
Person.prototype.sayHello = function() {
console.log("Hello, I'm " + this.firstName);
};
var person1 = new Person("Alice");
var person2 = new Person("Bob");
var helloFunction = person1.sayHello;
person1.sayHello();
person2.sayHello();
helloFunction();
console.log(helloFunction === person1.sayHello);
console.log(helloFunction === Person.prototype.sayHello);
helloFunction.call(person1);</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment