suggestions for additional javascript functionality

RESOLVED WONTFIX

Status

()

Core
JavaScript Engine
--
enhancement
RESOLVED WONTFIX
13 years ago
5 years ago

People

(Reporter: Felipe, Unassigned)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

(Reporter)

Description

13 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6

While functions are being added to SpiderMonkey, I thought of some ideas for new
extras:

-------------------
Array.prototype.sortBy: sorts an array by the output of a function to be mapped
onto the array. This also allows multi-level sorts: pass two or more functions
as parameters. Sort descending by assigning a "reverse" property to a function
passed as a parameter.

Array.prototype.combine: use "this" array as keys to a new Object, with an array
passed as a parameter used as values.

Date.prototype.format: UNIX date format. Right now, formatting dates in
javascript is really cumbersome.

Date.prototype.addInterval: Similar to MySQL's way of doing this.

Object.prototype.keys
Object.prototype.values: Both of these are pretty self-explanatory.
------------------

I've got implementations (in javascript) of all these up at the bug's URL.

Reproducible: Always

Comment 1

13 years ago
->Core: JS Engine
Assignee: nobody → general
Component: General → JavaScript Engine
OS: Windows 2000 → All
Product: Firefox → Core
QA Contact: general → general
Hardware: PC → All
Version: unspecified → Trunk
We should have a wiki-based process for fielding suggested additions.  The
ruby.js stuff is cool too, but we can't build all the suggested extensions in,
nor should we -- rather, we should include the necessary primitives, plus common
cliches and customs, and let the rest arise via a "JSAN" effort.

/be
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Reporter)

Comment 3

13 years ago
....except in ruby.js, they implement a lot of Object extensions by extending
the constructor's prototype. This is dangerous in Javascript, where the way to
iterate through an Object is

for (var key in someObj) {...}

....which, when I've tried extending the prototype, places the new prototype
members into this iteration. This actually caused extending Array.prototype to
break Dean Edwards's IE7 script until he got rid of "var i in someArray".

I'm all for a JSAN effort; the ideal would seem to be a service where, say, you
can request a JS file that has (for example) Array.prototype.sortBy, and it
spits back a file with that function plus any dependencies.
We generally prefer using Ecma for this nowadays. Object.keys is a thing \o/
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.