Boolean objects in conditionals

Mark S. Miller erights at google.com
Sat Nov 29 12:37:28 PST 2008


On Sat, Nov 29, 2008 at 5:40 AM, Lasse R.H. Nielsen <atwork at infimum.dk>wrote:

>  Number.prototype.box = function() {
>   return this;
>  };
>  var n = (42).box();
>
> I would prefer to have "this" refer to a basic value instead when calling
> "methods on primitive values".
> I.e.:
>  (42).toString()
> should not be equivalent to "new Number(42).toString()", but to something
> simliar to "Number.prototype.toString.call(42)" that actually uses "42"
> as the value of "this".
>
> Alas, that's probably too big a change for 3.1 :(
>


It's not too big a change from ES3.1-strict, but it may be too late. If it's
not too late, I would be in favor of this change. (I have previously
advocated this change on es-discuss.) Note that

    Number.prototype.box = function() {
      "use strict";
      return this;
    }
    var n = (42).box.call(42);

will correctly do what you want in ES3.1, so it seems a shame if we can't
fix the simpler form.

-- 
   Cheers,
   --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20081129/c04cf8a3/attachment.html>


More information about the Es-discuss mailing list