Is multiple inheritance possible in javascript? -
this question has answer here:
i have situation here. have 2 modules(nothing javascript function) defined this:
module1:
define(function(){ function a() { var = this; that.data = 1 // .. } return a; });
module2:
define(function(){ function b() { var = this; that.data = 1; // ... } return b; });
how inhert both modules inside other module?
1) in js object.
2) javascript inheritance uses prototype inheritance , not classic inheritance.
javascript doesn't support multiple inheritance. have both of them inside same class try use mixins better anyhow:
function extend(destination, source) { (var k in source) { if (source.hasownproperty(k)) { destination[k] = source[k]; } } return destination; } var c = object.create(null); extend(c.prototype,a); extend(c.prototype,b);
mixins:
http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/
inheritance in js:
http://howtonode.org/prototypical-inheritance
http://killdream.github.io/blog/2011/10/understanding-javascript-oop/index.html
Comments
Post a Comment