If I try this using standard Javascript instead of __defineGetter__, I get 
a more descriptive error when it fails (in Node only):
> Object.defineProperty(f, 'length', { get: function() { return 5; } });
TypeError: Cannot redefine property: length

And digging deeper:
> Object.getOwnPropertyDescriptor(f, 'length')
{ value: 3,
  writable: false,
  enumerable: false,
  configurable: false }

Looks like the version of V8 Node is using defines length as a 
non-configurable property.  In Chrome the same function says "configurable: 
true", so that behavior must have changed.

That being said, anything I've ever used which used the length of a 
function always causes headaches... various function composition functions, 
such as .bind will, depending on the version of V8 or Javascript engine (or 
other 3rd party modules which polyfill over the standard .bind) will often 
return a misleading result (on older versions of V8, and most 
polyfills, (function(a,b) {}).bind().length would be 0 instead of 2, since 
the return function isn't declared with any parameters).

  Jimb Esser

On Sunday, July 19, 2015 at 1:56:05 PM UTC-7, Robert Steckroth wrote:
>
> I need to override the length property of the Function constructor for a 
> wrapper I am making. Why does the following code work in Gecko and Mazilla 
> browsers but not nodejs?
>
> var f = function(a,b,c) {}
> f.length // = 3 <- length is three because 3 parameters are expected by 
> the function
>
> f.__defineGetter__("length", function() { return 5 })
> f.length // = 5 <- length is now five because f __proto__.length has been 
> overwritten with a property
>
> The above code works in the latest Chrome and Firefox but not in Nodejs, i 
> wonder why..
>
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/7fcc609e-6220-413b-bfca-cfd80fc44c5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to