오류 자바 스크립트 상속을 이해하기 위해이 코드를 실행하지만려고 :
SyntaxError: Using //@ to indicate source map URL pragmas is deprecated. Use //# instead
http://code.jquery.com/jquery-1.10.1.min.js
Line 1
TypeError: Class.extend is not a function
file:///home/prem/prototype/first.html
Line 13
HTML 파일의 코드 :
var Person = Class.extend({
init: function(isDancing){
this.dancing = isDancing;
},
dance: function(){
return this.dancing;
}
});
var Ninja = Person.extend({
init: function(){
this._super(false);
},
dance: function(){
// Call the inherited version of dance()
return this._super();
},
swingSword: function(){
return true;
}
});
var p = new Person(true);
p.dance(); // => true
var n = new Ninja();
n.dance(); // => false
n.swingSword(); // => true
// Should all be true
p instanceof Person && p instanceof Class &&
n instanceof Ninja && n instanceof Person && n instanceof Class
</script>
</head>
<body>
</body>
</html>
에게
어디에서'extend'을 정의합니까? 그건 네이티브 JavaScript가 아니기 때문에, 당신은 그 함수를 작성하거나 그렇게하는 라이브러리를 포함해야합니다. 백본'View.extend' 나 다른 프레임 워크의 상속 버전에서 코드를 모델링한다면, 그들은 특별히'extend' 메소드를 추가합니다. JavaScript에서 상속이 작동하는 방식이 아닙니다. – meagar
그럼, 뭐가 궁금한가요? 오류가 명확하지 않습니까? 상속을 이해하도록 상속을 설정하는 데 도움이되는 라이브러리는 사용하지 않을 것입니다. –
@Felix :이 오류를 어떻게 수정합니까? – user1050619