Open sophiebits opened 9 years ago
We could also prohibit new
and do it implicitly if we wanted to make the code feel Swift-ier. Lots of JS libraries actually do the implicit instantiation thing.
Looks great! Thanks, Ben!
I would vote for doing the implicit jnstantiation on user's behalf, since this is obviously what the user wanted to do anyway.
Ahaha way cool, @spicyj! Will dig into this in the next couple days (we're in NYC now for early math stuff hiiiiiiii)
My preference would be to throw an exception (as Ben's done) if the user leaves off the new
. I don't think it's a good idea to create variant dialects of JS—people using Prototope-JS should be able to refer to ordinary (and widely-available) JS resources to understand their environment.
@nsfmc? @jbrennan? Have opinions on that?
I'll get to work on productionizing this. How does "commandeering" work on GH? Do I just open up another PR?
Yup, another PR works
Sent from my iPhone
On 10 Mar 2015, at 06:12, Andy Matuschak notifications@github.com wrote:
My preference would be to throw an exception (as Ben's done) if the user leaves off the new. I don't think it's a good idea to create variant dialects of JS—people using Prototope-JS should be able to refer to ordinary (and widely-available) JS resources to understand their environment.
@nsfmc? @jbrennan? Have opinions on that?
I'll get to work on productionizing this. How does "commandeering" work on GH? Do I just open up another PR?
— Reply to this email directly or view it on GitHub.
My preference would be to throw an exception (as Ben's done) if the user leaves off the
new
.
+1
As a JS person (but not a Prototope person), I would not find it out of place to have these constructors not use new
at all. Lots of popular JS libraries have "constructors" that you call without new. Like jQuery has you write var foo = $.Deferred();
to create a promise-like object. I think my personal preference is to forbid new.
(Yeah, just open a new PR.)
(actually, as awesome as it is that @spicyj has sent us a prototype, integrating it while maintaining DRY will require some work; deprioritizing)
I did a bunch of the work here: https://github.com/Khan/Prototope/tree/pr/47
For #25: This shows how we might wrap the constructors so that they throw when called without
new
. In this example, I've hardcodedTextLayer
as the only wrapped type, but we'd presumably want to wrap every instantiable type. When you call a type withoutnew
, you now get a protonope, as you might expect. (It always says line 5 though since that's where thenew Error()
call is in the wrap script -- not sure how to fix that easily.)