Re: Logical operators don't use valueOf()

2013-09-08 Thread Marius Gundersen
So how about implementing toBoolean as an overridable method, which is called whenever !, || or are used. This way an objec has three method for converting it into a primitive; toString, toValue and toBoolean. Marius Gundersen On Sun, Sep 8, 2013 at 2:19 AM, Till Schneidereit

Re: Logical operators don't use valueOf()

2013-09-08 Thread Brendan Eich
Did you read my reply on this point? https://mail.mozilla.org/pipermail/es-discuss/2013-September/033234.html Anything unclear? /be Marius Gundersen mailto:gunder...@gmail.com September 8, 2013 3:47 AM So how about implementing toBoolean as an overridable method, which is called whenever !,

Re: Logical operators don't use valueOf()

2013-09-08 Thread Filip Pizlo
Never having a toBoolean hook would be quite constraining. The example from that e-mail involved: var huh = (obj || foo) bar; And the problem is that a valueOf or toBoolean hook on 'obj' could result in it being called multiple times, and since the hook is written in JS it could be

Re: Logical operators don't use valueOf()

2013-09-08 Thread Brendan Eich
Thanks for this reply. Filip Pizlo September 8, 2013 1:56 PM We have two choices:A) Reject the notion that 'obj' appearing once in the original source results in multiple calls to some hook on 'obj' (valueOf, toBoolean, whatever).B) Allow multiple calls along with

Re: Logical operators don't use valueOf()

2013-09-08 Thread Marius Gundersen
The only thing that is unclear is the reason memoizatation isn't used. It would seem to be the way most of the js engines would implement this anyways. I'm not familiar with the inner workings of JavaScript JIT engines, but in a situation like this, would that code not be compiled into something

Re: Logical operators don't use valueOf()

2013-09-08 Thread Brendan Eich
Marius Gundersen mailto:gunder...@gmail.com September 8, 2013 3:20 PM The only thing that is unclear is the reason memoizatation isn't used. It would seem to be the way most of the js engines would implement this anyways. This isn't an implementation question -- first we have to agree on

Logical operators don't use valueOf()

2013-09-07 Thread Marius Gundersen
While playing around with valueOf, I discovered that three operators (!, ||, ) don' seem to use valueOf when you use them. You can test this in your preferred browser here: http://lab.mariusgundersen.net/valueOf Is there a reason for this? Shouldn't these operators work the same way as the other

Re: Logical operators don't use valueOf()

2013-09-07 Thread Allen Wirfs-Brock
On Sep 7, 2013, at 9:10 AM, Marius Gundersen wrote: While playing around with valueOf, I discovered that three operators (!, ||, ) don' seem to use valueOf when you use them. You can test this in your preferred browser here: http://lab.mariusgundersen.net/valueOf Is there a reason for

Re: Logical operators don't use valueOf()

2013-09-07 Thread Brendan Eich
Marius Gundersen mailto:gunder...@gmail.com September 7, 2013 9:10 AM While playing around with valueOf, I discovered that three operators (!, ||, ) don' seem to use valueOf when you use them. You can test this in your preferred browser here: http://lab.mariusgundersen.net/valueOf Is there a

Re: Logical operators don't use valueOf()

2013-09-07 Thread Marius Gundersen
That's the way ToBoolean has always been defined http://people.mozilla.org/~jorendorff/es6-draft.html#sec-7.1.2 . All objects are considered to be Boolean true values. So does this mean I can override toBoolean to change the way ! behaves on an object? Marius Gundersen

Re: Logical operators don't use valueOf()

2013-09-07 Thread Till Schneidereit
On Sun, Sep 8, 2013 at 2:15 AM, Marius Gundersen gunder...@gmail.comwrote: That's the way ToBoolean has always been defined http://people.mozilla.org/~jorendorff/es6-draft.html#sec-7.1.2 . All objects are considered to be Boolean true values. So does this mean I can override toBoolean to