Hi...wondering if this is possible for the method.
I know util.inherits() might be implemented in this way.
function inherits(constructor, super){
constructor.prototype = Object.create(super.prototype);
constructor.prototype.constructor = constructor;
constructor.super_ = super;
}
I am wondering if it could be changed to the following way:
function inherits(constructor, super){
constructor.prototype.__proto__ = super.prototype;
constructor.super_ = super;
}
The main difference is the second implementation won't change the
constructor.prototype, and the benefit is we can use module.exports more
flexible, e.g.
var AsLinker = require("./AsLinker");
module.exports = new SomeLinker(); // put the module.exports line in the
beginning of the script
function SomeLinker(){
AsLinker.call(this);
}
SomeLinker.prototype.link = function(){ // override the parent method };
Since the SomeLinker.prototype is the original one, we can still update the
SomeLinker.prototype after module.exports = new SomeLinker();
In the current implementation of util.inherits(), we must move the
module.exports = new SomeLinker() to the bottom of the script after the
method is added to the SomeLinker.prototype.
Or the instance of SomeLinker will have no chance to get the new prototype.
Just a thought to improve the convenience of Node.js coding, apologized if
I am wrong, since I know it's been locked status. But the interface is the
same, maybe it could be changed :)
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.