For me

  setTimeout(function() { console.log(x) }, 5000)

is cleaner than

  setTimeout(console.log.bind(console, x), 5000)

I used .bind() a lot to get rid of scope-problems for once and all
times. But then the code became, well, a mess: Everything I saw was
calls to .bind() ;-) Way too much noise. And it did not really solve
every scope-problem for once and all times.

Now I use .bind() when it is really necessary.



On Tue, May 29, 2012 at 12:27 PM, Mariusz Nowak <[email protected]> wrote:
> Use what works for you, and don't bother with premature optimization.
>
> By the way it's not greatest bind use case, I wouldn't use bind here. In
> some older versions of node (v0.6.3 ?) , setTimeout passes one argument to
> the callback, and in your example it will be logged as well.
>
>
> On Tuesday, May 29, 2012 2:52:46 AM UTC+2, phidelta wrote:
>>
>> Hi all,
>>
>> I have recently come to use .bind a lot, because it makes for very
>> clean code.
>>
>> So rather than doing
>>
>> <code>
>> var x; // this has some value that comes from prior code
>> setTimeout(function() { console.log(x) }, 5000);
>> </code>
>>
>> I am now often doing
>>
>> <code>
>> var x;
>> setTimeout(console.log.bind(console, x), 5000);
>> </code>
>>
>> The question I have is: what is more performant? Is there any reason
>> to avoid .bind()?
>>
>> Regards, Phil
>
> --
> 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



-- 
Oliver Leics @ G+
https://plus.google.com/112912441146721682527

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

Reply via email to