Sugar for *.prototype and for calling methods as functions

Mariusz Nowak medikoo+mozilla.org at medikoo.com
Tue Feb 21 03:16:23 PST 2012


Sorry if it already has been picked up (I searched and didn't found anything
close that).

In my last months of work with JavaScript what that I miss a lot in ES5
syntax is:

1. Syntax shortcut for '.prototype'. Instead of writing
String.prototype.trim I'd love to be able to write for example String#trim 
(it's not proposal, just example how it may look).
As most native ES methods are generic there are a lot of valid use cases for
that e.g.:

Array#foEach.call(listThatsNotArray, fn);

2. Syntax sugar for calling method as a function. In following examples I
just place '@' at end of method that I'd like to be run as function.

Array#forEach@(listThatsNotArray, fn));

or 

trimmedListOfStrings = listOfStrings.map(String#trim@);

Last example is same as following in ES5:

trimmedListOfStrings =
listOfStrings.map(Function.prototype.call.bind(String.prototype.trim));

This two proposals will make methods easily accessible for some functional
constructs, and I think might be revolutionary for those who favor such
functional way of programming.

Let me know what do you think about that.

-- 
Mariusz Nowak
https://github.com/medikoo
http://twitter.com/medikoo

-----
Mariusz Nowak

https://github.com/medikoo
-- 
View this message in context: http://old.nabble.com/Sugar-for-*.prototype-and-for-calling-methods-as-functions-tp33363174p33363174.html
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com.



More information about the es-discuss mailing list