> On Oct 27, 2015, at 2:37 AM, Claude Pache <claude.pa...@gmail.com> wrote: > > > Naturally, I meant: > > ```js > Function.isGenerator = function (f) { > return typeof f == "function" && f.toString().match(/^function\s*\*/) != > null > } > ``` > > —Claude > >> >> That function will work (in the sense of: will return an answer; I'm not >> judging the quality of that answer) with anything reasonable fed to it >> (where "reasonable" excludes things like `(class { static toString() { throw >> "pwnd!" }})`). Well, ... until a proxy for a function is encountered. >> >> —Claude
This may have been pragmatically useful but it has never been a reliable test because there was nothing that stops somebody from adding an arbiietrary `toString` own property to f or from using dunder photo to change the prototype used to supply `toString`. Also, going back to at lest ES3, F.p.toString was specified to throw a TypeError when applied to an object that “is not Function object”. That said, I think it is plausible that the predicate in step 2 of http://tc39.github.io/ecma262/#sec-function.prototype.tostring <http://tc39.github.io/ecma262/#sec-function.prototype.tostring> could be replaced with: IsCallable(func) Allen
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss