4 ms·
Yeah, I'll admit that's a bit confusing. I did want to provide a way do something like Object.create in environments where it's not available. This way you ca
by jayferd 15y ago
Yeah, I'll admit that's a bit confusing. I did want to provide a way do something like Object.create in environments where it's not available. This way you can do `MySubclass.prototype = new MyClass` and not have to worry about the initializer.
- jayferd 15y ago(apologies for the double post) Doing away with `new` in this way also has the added advantage of allowing people to create objects with varargs, which is impossible otherwise.
- ricardobeat 15y agonew MyClass('bacon', 'eggs') is perfectly possible, or am I misunderstanding your sentence? How about exposing creation via `P.create`, `P.inherit` or something like it?
- jayferd 15y agoright, but say you had an `var array = ['bacon', 'eggs']`. You can call a function with these arguments with `fn.apply(null, array)` (yeah it's ugly but it's how it's done in JS). This doesn't work with the `new` keyword. EDIT: also, a class method would hurt your script's minifier performance. ...and at that point you may as well just call the function anyways :)