'@std' and non-method versions of various methods?

Brandon Benvie brandon at brandonbenvie.com
Mon Dec 24 13:21:45 PST 2012


While seemingly out of date (though looks to have been updated recently),
the modules_standard proposal is still listed as ostensibly part of harmony
(ES6). For the most part it simply lists all the standard builtins from
chapter 15 but there's a few new things in here. What caught my eye a while
back specifically was the non-method versions of call, bind, and apply as
part of '@function'. While these three are particularly useful as
non-method versions, I think the usefulness clearly extends beyond this
small selection to at least the most commonly used ones (I'm thinking of
Array.prototype.push, Object.prototype.toString, etc.) that aren't covered
by other new ES6 functionality (like hasOwnProperty is covered by
'@reflect').

In particular, non-method versions of all the Map, Set, and WeakMap
methods, along with most of Array methods, would be very useful. A non
"method" version of the constructor itself, like mapCreate(object,
iterable), would be useful. The collection methods are similar to the Array
methods. Not because they work generically like the Array methods do, but
because any object can (given proper initialization) be the target of these
methods.

Following the pattern described by the modules_standard proposal, these
would simply live along side the constructor when importing the module. So,
for example (I'm sure I'm getting the module syntax wrong since it's been
changing, but you'll get the idea);

    module map = '@map';

    var obj = {};
    map.create(obj);
    map.set(obj, key, val);
    console.log(map.size(obj));


Or for the more mundane Array

    import { push } from '@array';
    var obj = { length: 0 };
    push(obj, 1, 2, 3);




http://wiki.ecmascript.org/doku.php?id=harmony:modules_standard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121224/21f5eaf1/attachment.html>


More information about the es-discuss mailing list