I don't think this part of JavaScript will ever change.  Node does not
modify the JavaScript language it uses.

Lua does this though if you want to try luvit.io (node ported to lua).  It
has syntax sugar to make defining and calling context-first methods easier.

    -- This is lua code, not JS
    local Point = {}

    -- constructor
    function newPoint(x, y)
      local obj =setmetatable({}, Point)
      -- This is really obj.initialize(obj, x, y)
      obj:initialize(x, y)
    end

    -- This is really Point.initialize = function (self, x, y) ...
    function Point:initialize(x, y)
      self.x = x
      self.y = y
    end


I think a more relevant question for the node list would be preference in
using "this" and shared function prototypes vs storing state in closures.
 I find both patterns very useful in node code and I often mix them.

On Tue, May 29, 2012 at 8:07 AM, Felipe Gasper <[email protected]>wrote:

> (Slightly OT for this list, but...)
>
> Just curious, was there, is there ongoing, a discussion of the prudence of
> having a context object in the first place?
>
> IMO, Perl does this the right way: the namespace/$this is just the first
> argument that the function receives; i.e., $obj->func('foo') will receive
> args of ( $obj, 'foo' ).
>
> -FG
>
>
> On 29.5.12 5:56 AM, Oliver Leics wrote:
>
>> 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<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
>>> nodejs+unsubscribe@**googlegroups.com<nodejs%[email protected]>
>>> For more options, visit this group at
>>> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en>
>>>
>>
>>
>>
>>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/**node/wiki/Mailing-List-**
> 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
> nodejs+unsubscribe@**googlegroups.com<nodejs%[email protected]>
> For more options, visit this group at
> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en>
>

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