-
-
Save sumitramteke/079e42645b4068086f76 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/kuruku
This file contains hidden or 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
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); |
This file contains hidden or 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
<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