Im trying to run this code to understand Javascript inheritance but get an error
Error:
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 file code:
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? That's not native JavaScript, you need to either write that function or include a library that does. If you're modeling your code on BackboneView.extendetc, or another framework's version of inheritance, they specifically add anextendmethod. That's not how inheritance works in JavaScript.Class.extendis not a function. So maybe you have to call a different function. Or include a different library which definesClass.extend. Since you don't explain which library you are using and whereClasscomes from, there really is not much else to say.