Closed simoami closed 10 years ago
Consider the following inheritance patterns in Javascript:
The classic way:
var Base = function(config) { this.config = config }; Base.prototype.method1 = function(cb) { cb(); }; Base.prototype.method2 = function(cb) { cb(); }; var ChildClass = function(config) { this.config = config; this.prop = true; }; ChildClass.prototype = new Base(); ChildClass.prototype.constructor = ChildClass; ChildClass.prototype.method3 = function(cb) { cb(); }; ChildClass.prototype.method4 = function(cb) { cb(); };
The constructor-less inheritance using ES5 Object.create
var Base = { create: function create() { var instance = Object.create(this); instance._construct.apply(instance, arguments); return instance; }, extend: function extend(properties, propertyDescriptors) { propertyDescriptors = propertyDescriptors || {}; if(properties){ var simpleProperties = Object.getOwnPropertyNames(properties); for (var i = 0, len = simpleProperties.length; i < len; i += 1) { var propertyName = simpleProperties[i]; if(propertyDescriptors.hasOwnProperty(propertyName)) { continue; } propertyDescriptors[propertyName] = Object.getOwnPropertyDescriptor(properties, propertyName); } } return Object.create(this, propertyDescriptors); }, _construct: function _construct() {}, method1: function method1(cb) { cb(); }, method2: function method2(cb) { cb(); } }; var ChildClass = Base.extend({ method3: function(cb) { cb(); }, method4: function(cb) { cb(); } });
Can you recommend a good way to plug async chaining for ChildClass in both use-cases?
Thanks in advance!
@simoami I do not have an easy answer for you. If somethind is wrong with the lib, open another issue.
@vvo Thanks for replying. No worries. I've built this functionality here.
Consider the following inheritance patterns in Javascript:
The classic way:
The constructor-less inheritance using ES5 Object.create
Can you recommend a good way to plug async chaining for ChildClass in both use-cases?
Thanks in advance!