2016년 2월 20일 토요일

[JavaScript] make object

//생성자 정의 통한 객체 생성
function Person (name, age) [
     this.name = name;
     this.age = age;

     this.hi = function() {
          console.log("hi" + name);
     }
}

//정적 속성
Person.PLANET = "earth";

//생성자 외부에서 멤버 함수 정의
Person.prototype.yo = function() {
    console.log(this.name + " yo");
}


var lee = new Person("lee", 1);
lee.hi();
lee.yo();


댓글 없음:

댓글 쓰기