oop - Why my extend() method in Javascript don't work for 3 and more objects? -
i have 3 object.
netbuilder numbering numberingmethoddefault
and have extend method.
extend: function (child, parent) { var f = function () {}; f.prototype = parent.prototype; child.prototype = new f(); child.prototype.constructor = child; child.superclass = parent.prototype; this.mixin(child, parent); }, /** * @param {type} dst * @param {type} src * @returns {undefined} */ mixin: function (dst, src) { var tobj = {}; (var x in src) { if ((typeof tobj[x] == "undefined") || (tobj[x] != src[x])) { dst[x] = src[x]; } } if (document.all && !document.isopera) { var p = src.tostring; if (typeof p == "function" && p != dst.tostring && p != tobj.tostring && p != "\nfunction tostring() {\n [native code]\n}\n") { dst.tostring = src.tostring; } } }
than try numbering extends netbuilder , numberingmethoddefault extends numbering.
ooputility.extend(numbering, netbuilder); ooputility.extend(numberingmethoddefault, numbering);
and call superclassses
numbering.superclass.constructor.call(this, arguments); numberingmethoddefault.superclass.constructor.call(this, arguments);
numbering has method setnumber(). have access in numbering netbuilder methods, in numberingmethoddefault can't execute method setnumber() numbering.
uncaught typeerror: object #<numberingmethoddefault> has no method 'setnumber'
than console.log() superclass numberingmethoddefault
console.log(numberingmethoddefault.superclass); //and netbuilder, not numbering! о_О
how can make work. need extend 3 or more objects!
this because call mixin
manually copies properties 1 object other, , overwriting .superclass
assignment. if you're emulating class inheritance won't need mixins in way, remove code altogether , shouldn't have problem.
Comments
Post a Comment