Skip to content

Instantly share code, notes, and snippets.

@pocojang
Last active May 1, 2018 21:13
Show Gist options
  • Save pocojang/33676252f81d0078943e93485f2e05ca to your computer and use it in GitHub Desktop.
Save pocojang/33676252f81d0078943e93485f2e05ca to your computer and use it in GitHub Desktop.
prototype & constructor
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