0
커피 스크립트 코드 : 여기클래스가 부모 클래스의 "instanceof"가 아닌 이유는 무엇입니까?
class Animal
constructor: (@name) ->
move: (meters) ->
alert @name + " moved #{meters}m."
class Snake extends Animal
move: ->
alert "Slithering..."
super 5
alert Snake instanceof Animal
이 a link입니다.
정말이 결과가 사실이라고 생각합니다. 부모가
__extends = function (child, parent) {
for(var key in parent) {
if(__hasProp.call(parent, key)) child[key] = parent[key];
}function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.__super__ = parent.prototype;
return child;
};
child.prototype.prototype
입니다 : 그리고 내 이유는 컴파일 된 자바 스크립트에서이 __extends
방법이다.
누군가 내게 이유를 말해 줄 수 있습니까? 는 그리고 아래 아는 사실이다 :
class Snake extends Animal
Snake
(는 "클래스") 실제로 Function
하지 Animal
의 인스턴스 인 것을 의미한다 :
alert new Snake('a') instanceof Animal