jquery와 같은 확장 메소드와 같은 키워드 (또는 메소드?) 프로토 타입입니까?키워드 프로토 타입은 jquery에서 정확히 무엇을 수행합니까?
즉 모든 클래스에서 앞으로이 기능을 사용할 수 있습니까?
jquery와 같은 확장 메소드와 같은 키워드 (또는 메소드?) 프로토 타입입니까?키워드 프로토 타입은 jquery에서 정확히 무엇을 수행합니까?
즉 모든 클래스에서 앞으로이 기능을 사용할 수 있습니까?
이것은 자바 스크립트의 일부이며 jquery에만 국한되지 않습니다.
prototype
속성은 해당 유형의 모든 개체에서 공유하는 메서드와 속성을 정의합니다.
MyClass
의
function MyClass()
{
}
myClass.prototype.myMethod = function()
{
alert("hello world");
}
var myObject = new MyClass();
myObject.myMethod();
모든 인스턴스는 (주) 방법 myMethod()
있을 것이다.
프로토 타입의 메서드는 생성자 내에서 선언 된 메서드와 동일한 가시성을 갖지 않습니다.
예를 들어:
function Dog(name, color)
{
this.name = name;
this.getColor = function()
{
return color;
}
}
Dog.prototype.alertName = function {
alert(this.name);
}
Dog.prototype.alertColor = function {
//alert(color); //fails. can't see color.
//alert(this.color); //fails. this.color was never defined
alert(this.getColor()); //succeeds
}
var fluffy = new Dog("Fluffy","brown");
prototype
는 jQuery를 키워드 아니다; Javascript 키워드입니다. 이 함수는 객체의 새 인스턴스를 만들 때마다 존재하는 방식으로 객체에 public 함수를 추가하는 데 사용됩니다.
http://meta.stackoverflow.com/search?q=lmgtfy –