Hello, I had a problem with how to do inheritance when declaring prototypes of objects with object literal syntax.
I made two feeds to help you help.
This is my base class, almost all objects are defined this way in my application:
Base = function(param){
this.init(param);
}
Base.prototype = {
init: function(param){
this.param = param;
},
calc: function(){
var result = this.param * 10;
document.write("Result from calc in Base: " + result + "<br/>");
},
calcB: function(){
var result = this.param * 20;
document.write("Result from calcB in Base: " + result+ "<br/>");
}
}
Here's how I manage to extend and override methods in Base:
Extend = function(param){
this.init(param);
}
Extend.prototype = new Base();
Extend.prototype.calc = function(){
var result = this.param * 50;
document.write("Result from calc in Extend: " + result+ "<br/>");
}
But I wanted to use the same style as the rest of the application, so I started playing with object literals, but it makes me happily cheer on eclipse and firebug with my meaningless answer to my syntax.
, ?
( , , , .)
Extend = function(param){
this.init(param);
}
Extend.prototype = {
: new Base(),
calc: function(){
var result = this.param * 50;
document.write("Result from calc in Extend: " + result+ "<br/>");
}
}