객체에서 호출 될 때 Javascript가 프로토 타입 체인에서 함수를 처리하는 방법을 배우려면 this article on Helephant.com을 참조합니다. 객체가 직접 설정하는 방법이없는 경우Object.prototype에 대한 프로토 타입 체인의 함수 해상도가 생성자로 작동하는 방법
기사 시세,
, 자바 스크립트는 개체를 만든 생성자 함수를 찾습니다. Javascript는 메소드의 생성자의 프로토 타입 속성을 확인합니다. 다음 코드에서
, 당신은 rufus.constructor
글로벌 Object()
생성자 확인, 그래서 직접 JS rufus.constructor
이 Object()
때문에) (글로벌 객체를 확인하거나 문서 인용에 따라 처음 생성자 볼 것이다 위 않을 경우 그러면 prototype 프라퍼티를 찾으십시오. JS가 어떻게 함수를 해결할 것입니까 (rufus.toString
). 나는 이것에 확실히 혼동된다.
//PET CONSTRUCTOR
function Pet(name, species, hello)
{ this.name = name;
this.species = species;
this.hello = hello; }
Pet.prototype = {
sayHello : function(){
alert(this.hello);
}
}
//CAT CONSTRUCTOR
function Cat(name, hello, breed, whiskerLength)
{ this.name = name;
this.hello = hello;
this.breed = breed;
this.whiskerLength = whiskerLength;}
Cat.prototype = new Pet();
var rufus = new Cat("rufus", "miaow", "Maine Coon", 7);
rufus.toString;
은 아직 아무것도 확실하지가 :
toString
방법은 해결 방법에 대해서 :이 같은 프로토 타입을 설정할 수 있습니까? –