An implementation of new using new is kind of weird... On Jul 16, 2011 1:54 AM, "Dmitry Baranovskiy" <[email protected]> wrote: > I would suggest to fix prototype reference and ensure that all objects that > are returned from constructor are taken into account be it functions or > anything else. Something across these lines: > > function NEW(f) { > var obj, > out; > if (Object.create) { > obj = Object.create(f.prototype); > } else { > NEW.ff = NEW.ff || function () {}; > NEW.ff.prototype = f.prototype; > obj = new NEW.ff; > } > out = f.apply(obj, Array.prototype.slice.call(arguments, 1)); > if (Object(out) === out) { > return out; > } > return obj; > } > > > On 15 July 2011 22:12, Peter van der Zee <[email protected]> wrote: > >> On Fri, Jul 15, 2011 at 1:38 PM, Xavier MONTILLET >> <[email protected]> wrote: >> > Hi, >> > >> > I think you should je return whaterver is returned by the constructor. >> >> Nah, construtors always return an object. If you don't (ie. `return >> 5;`), the original new instance is returned anyways. >> >> I would suggest you use a blacklist for primitives with typeof though, >> since host objects and function do not (have to) return "object". And >> also check for null, since that returns "object" as well. For future >> proofing, also check if typeof returns "null", because that will be >> fixed later. >> >> Other than that, yeah looks fine. Important part is fixing the >> [[Prototype]] reference. Maybe you could create the new object with >> Object.create so that it works in all es5 compliant browsers? I >> wouldn't rely on __proto__ too much. Maybe try to fall back to >> __proto__ if Object.create does not exist. >> >> - peter >> >> -- >> To view archived discussions from the original JSMentors Mailman list: >> http://www.mail-archive.com/[email protected]/ >> >> To search via a non-Google archive, visit here: >> http://www.mail-archive.com/[email protected]/ >> >> To unsubscribe from this group, send email to >> [email protected] >> > > > > -- > Best regards, > Dmitry Baranovskiy > http://dmitry.baranovskiy.com > > -- > To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected]
-- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
