We're not going to change util.inherits any time in the foreseeable future.

Feel free to implement your own thing and share it on npm.


On Tue, Mar 5, 2013 at 12:33 AM, greelgorke <[email protected]> wrote:

> Your version makes the prototype chain longer, which may have a
> performance impact on some important parts of the lib. Please Correct me if
> i'm wrong, but this could produce chains:
> CustomStream->(ReadableStream->) Stream->EventEmitter->Object.prototype
> vs new one:
> CustomStream->CustomStream.prototype->(ReadableStream->ReadableStream.prototype->)
> Stream->Stream.prototype->EventEmitter->EventEmitter.prototype->Object.prototype
>
> in your particular example you create a singleton. this can be done in
> this way too:
>
> var    AsLinker = require("./AsLinker");
>
> module.exports = {}
>
> module.exports.__proto__ = new AsLinker()
>
> module.exports.link = function(){ // override the parent method };
>
>
> or even like this:
>
> var    AsLinker = require("./AsLinker"), linker = new AsLinker();
>
> module.exports = linker;
>
> //if you want to do super.link prepare for it:
> var superLink = linker.link;
>
> module.exports.link = function(){ // override the parent method
>   var superResult = superLink.apply(this,arguments);
>   //do more with superResult
>  };
>
> other usecases? i don't think the change would make any better than
> current solution. the only feature, to be flexible with the position of
> module.exports seems not important to me. it's less important where it is,
> but more important that all modules put this line in the same position (i
> do on the bottom). and if you write one-function-modules, you never have to
> bother about the position anyway.
>
>
>
> Am Dienstag, 5. März 2013 06:24:07 UTC+1 schrieb [email protected]:
>
>>   Post reply
>> [image: More message actions]
>>  1:19 PM (1 minute ago)
>>   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    util = require("util"),
>>         AsLinker = require("./AsLinker");
>>
>> module.exports = new SomeLinker(); // put the module.exports line in the
>> beginning of the script
>>
>> function SomeLinker(){
>>
>>     AsLinker.call(this);
>> }
>>
>> util.inherits(SomeLinker, AsLinker);
>>
>> 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.
>
>
>

-- 
-- 
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.


Reply via email to