'this' is more complicated than I thought (PropertyReferences break equivalences)

2011-04-11 Thread Claus Reinke
Like most Javascript programmers, I have tended to follow a simple rule for functions using 'this': eta-expand method selections, use .bind, or get into trouble. Then I got curious about how method calls determine what object to pass as 'this': a method is a function selected from an object,

Re: Setting a property in the prototype chain?

2011-04-11 Thread Jorge
On 11/04/2011, at 05:14, Mark S. Miller wrote: On Apr 10, 2011, at 22:18 , David Herman wrote: function getDefiningObject(obj, key) { if (!(key in obj)) throw new Error(key + key + not found); while (!obj.hasOwnProperty(key)) That should be while

Re: 'this' is more complicated than I thought (PropertyReferences break equivalences)

2011-04-11 Thread Lasse Reichstein
The behavior of References isn't as arbitrary or different from other languages as it might seem. It's really a way to specify l-values. When you assign to an object property, e.g., o.x = 42, the l-value here is the x property of the o object. We need to capture both. In other languages,

Re: Dependency injection and modules?

2011-04-11 Thread Axel Rauschmayer
I'm not sure how this would be done best or how useful it would be, but: has dependency injection been considered as a use case for modules (e.g. to swap modules during testing)? One possibility might be to give modules parameters that module clients have to provide. The module system

When is a JavaScript program correct? (was: Setting a property in the prototype chain?)

2011-04-11 Thread Mark S. Miller
On Sun, Apr 10, 2011 at 11:21 PM, David Herman dher...@mozilla.com wrote: I wondered if someone was going to make this point. That should be while (!{}.hasOwnProperty.call(obj, key)) which works even if obj has an own property named 'hasOwnProperty'. Not if someone mutates

Re: Dependency injection and modules?

2011-04-11 Thread Nathan Stott
Could you, or someone else, please explain what changing the semantics of module URLs means? DI is an important issue and I'd like to understand how it is intended to be achieved in the future module system. On Mon, Apr 11, 2011 at 8:52 AM, Axel Rauschmayer a...@rauschma.de wrote: I'm not sure

Re: Dependency injection and modules?

2011-04-11 Thread Axel Rauschmayer
My understanding is limited, but here it goes: You load modules in ES.next as follows: module JSON = require('http://json.org/modules/json2.js'); A custom module loader (loosely related to a Java class loader) can be used to intercept the module loading and return a different module. That is,

Re: When is a JavaScript program correct? (was: Setting a property in the prototype chain?)

2011-04-11 Thread Dmitry A. Soshnikov
On 11.04.2011 18:07, Mark S. Miller wrote: On Sun, Apr 10, 2011 at 11:21 PM, David Herman dher...@mozilla.com mailto:dher...@mozilla.com wrote: I wondered if someone was going to make this point. That should be while (!{}.hasOwnProperty.call(obj, key))

Re: Setting a property in the prototype chain?

2011-04-11 Thread Allen Wirfs-Brock
Personally, I prefer Object.getOwnPropertyDescriptor as a property existence test because it doesn't have the reflection the meta-circularity concern. I would write Dave's original function as: function getDefiningObject(obj, key) { var obj={}.valueOf.call(obj); // ToObject in case

Re: When is a JavaScript program correct? (was: Setting a property in the prototype chain?)

2011-04-11 Thread David Bruant
Le 10/04/2011 23:27, Dmitry A. Soshnikov a écrit : On 11.04.2011 18:07, Mark S. Miller wrote: On Sun, Apr 10, 2011 at 11:21 PM, David Herman dher...@mozilla.com mailto:dher...@mozilla.com wrote: I wondered if someone was going to make this point. That should be

Re: When is a JavaScript program correct? (was: Setting a property in the prototype chain?)

2011-04-11 Thread Mark S. Miller
On Sun, Apr 10, 2011 at 5:27 PM, Dmitry A. Soshnikov dmitry.soshni...@gmail.com wrote: As I see it, you address the issue of unstratified meta-programming (note, I take the issue in quotes, since there's no a single meaning whether the unstratified meta-level is so bad). It depends on how

Re: ECMAScript Object equivalence classes proposal

2011-04-11 Thread Erik Arvidsson
On Fri, Apr 8, 2011 at 13:24, Brendan Eich bren...@mozilla.com wrote: On Apr 8, 2011, at 12:59 PM, David Bruant wrote: I'll agree that as long as it's fast enough for real life uses, the actual big-O or multiplicative constants are of no interest. For instance, the current inheritance has a

Re: When is a JavaScript program correct? (was: Setting a property in the prototype chain?)

2011-04-11 Thread Mike Samuel
2011/4/11 Mark S. Miller erig...@google.com: We would like a notion of correctness that allows us to reason in a modular manner: A correct composition of individually correct components should yield a correct composite, where the correctness of the composition depends only on the contracts of

Re: When is a JavaScript program correct? (was: Setting a property in the prototype chain?)

2011-04-11 Thread Mark S. Miller
On Mon, Apr 11, 2011 at 2:48 PM, Mike Samuel mikesam...@gmail.com wrote: 2011/4/11 Mark S. Miller erig...@google.com: We would like a notion of correctness that allows us to reason in a modular manner: A correct composition of individually correct components should yield a correct

Re: Setting a property in the prototype chain?

2011-04-11 Thread Brendan Eich
On Apr 11, 2011, at 8:58 PM, David Bruant wrote: Le 11/04/2011 21:47, Brendan Eich a écrit : On Apr 11, 2011, at 6:36 PM, Allen Wirfs-Brock wrote: Personally, I prefer Object.getOwnPropertyDescriptor as a property existence test because it doesn't have the reflection the meta-circularity

Re: Setting a property in the prototype chain?

2011-04-11 Thread Allen Wirfs-Brock
On Apr 11, 2011, at 12:47 PM, Brendan Eich wrote: Then the only downside is the pd allocation. Any way to avoid that? /be Use a GC that supports cheap allocation/recovery of short-lived objects :-) It's probably premature optimization to worry about that one pd allocation without

Re: Setting a property in the prototype chain?

2011-04-11 Thread David Bruant
Le 11/04/2011 22:01, Brendan Eich a écrit : On Apr 11, 2011, at 8:58 PM, David Bruant wrote: Le 11/04/2011 21:47, Brendan Eich a écrit : On Apr 11, 2011, at 6:36 PM, Allen Wirfs-Brock wrote: Personally, I prefer Object.getOwnPropertyDescriptor as a property existence test because it

Re: Setting a property in the prototype chain?

2011-04-11 Thread Brendan Eich
On Apr 11, 2011, at 9:21 PM, David Bruant wrote: Actually I was wrong I think. With the introduction of proxies, ES engines won't be able to trivially prevent pd allocation as they could with regular objects just based on static analysis (since static analysis will often fail at saying

Re: When is a JavaScript program correct? (was: Setting a property in the prototype chain?)

2011-04-11 Thread David Herman
Sure, I'll buy that. There's a qualitative difference in how uncooperatively your program is behaving if it mutates primordials to violate their usual contracts, as opposed to simply creating an object that overrides hasOwnProperty, which ought to be allowed. The word theory might be a little

Re: Dependency injection and modules?

2011-04-11 Thread David Herman
Yes, that's the idea. Best, Dave On Apr 11, 2011, at 7:45 AM, Axel Rauschmayer wrote: My understanding is limited, but here it goes: You load modules in ES.next as follows: module JSON = require('http://json.org/modules/json2.js'); A custom module loader (loosely related to a Java

Re: 'this' is more complicated than I thought (PropertyReferences break equivalences)

2011-04-11 Thread Garrett Smith
On 4/11/11, Claus Reinke claus.rei...@talk21.com wrote: Like most Javascript programmers, I have tended to follow a simple rule for functions using 'this': eta-expand method selections, use .bind, or get into trouble. That is unnecessary and inefficient. Instead, I use the following algorithm:

Re: 'this' is more complicated than I thought (PropertyReferences break equivalences)

2011-04-11 Thread Garrett Smith
On 4/11/11, Claus Reinke claus.rei...@talk21.com wrote: Like most Javascript programmers, I have tended to follow a simple rule for functions using 'this': eta-expand method selections, use .bind, or get into trouble. That is unnecessary, inefficient, and adds clutter. That most JavaScript

Re: value proxies, fundamental traps for binary operators, precedence

2011-04-11 Thread Brendan Eich
On Apr 8, 2011, at 11:29 AM, Claus Reinke wrote: I finally got a first look at the 'Virtual Values for Language Extension' paper referred to in the value proxies strawman [1], and suddenly find value proxies more interesting. Somehow the term proxy never suggested to me that this would

Re: Setting a property in the prototype chain?

2011-04-11 Thread Axel Rauschmayer
var obj={}.valueOf.call(obj); // ToObject in case primitive value passed Can you explain how this works? - Why {} and not Object.prototype? - I know valueOf as a method that returns a primitive if an object can be converted to one and |this|, otherwise. Oddly enough, this works both in

Re: Setting a property in the prototype chain?

2011-04-11 Thread Allen Wirfs-Brock
On Apr 11, 2011, at 6:45 PM, Axel Rauschmayer wrote: var obj={}.valueOf.call(obj); // ToObject in case primitive value passed Can you explain how this works? - Why {} and not Object.prototype? - I know valueOf as a method that returns a primitive if an object can be converted to one