Function.prototype.toString to discover function dependencies

James Burke jrburke at gmail.com
Wed Sep 29 12:13:40 PDT 2010


On Wed, Sep 15, 2010 at 5:24 PM, James Burke <jrburke at gmail.com> wrote:
> Is this an acceptable use of Function.prototype.toString? What
> problems would there be now or in the future?

For the record, the PlayStation 3's browser returns a
Function.prototype.toString like:

function (require, exports, modue) { /*-2134160600*/ }

I went ahead and added support for this toString approach in the
latest RequireJS release though, so it can be used in real projects,
and to see if it helps smooth out the CommonJS/browser bumps.

For platforms that have give unusable Function.prototype.toString()
values, there are two options to get the code to run:

1) use the RequireJS optimization tool that will pull out the
dependencies and normalize the modules to the base module format that
has dependencies specified as an array outside the  module definition
function.

2) code in the base module format.

James


More information about the es-discuss mailing list