Last active
May 1, 2018 21:13
-
-
Save pocojang/33676252f81d0078943e93485f2e05ca to your computer and use it in GitHub Desktop.
prototype & constructor
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
function Person(name) { | |
// 생성자내에서만 사용가능 | |
var age = 30; | |
this.name = name; | |
// 인스턴스 생성시 계속 생성됨 | |
this.greeting = function() { | |
return this.name; | |
}; | |
} | |
// 공유자원으로 사용가능 어떠한 인스턴스라도 | |
Person.prototype.greeting = function() { | |
return this.name; | |
}; | |
var person1 = new Person('ABC'); | |
var person2 = new Person('DEF'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment