Closed benpptung closed 9 years ago
+1
-1
I consider this syntactic sugar as unnecessary. Also, there are various mechanisms to extend Ractive in various ways, for example with components. Dunno if this would be a problem or not. Lastly, with new
it is clearer that you create an instance rather than invoking a function or a singleton.
@dagnelies, I understand what you mean. I would like to explain it more in detail. In fact, it won't force you to drop new
. It is just an additional way for developers who are used to node.js style coding. In node.js, it is a very common style, even in its core api, e.g. Buffer. After being familiar to it, it is really hard to write a new
before a constructor.
There certainly is some popularity in the js community with that convention, and it would be entirely elective.
While the cost of the instanceof
check seems low (thousandths to hundredths of a ms), I would prefer to not to incur the cost on template instantiated components, just developer new
instantiations. So I'd need to look at the code, but I think that's doable.
Biggest thing is for people who would like this to chime in. Generally one-off preferences are better as self-extensions.
I would prefer to not to incur the cost on template instantiated components, just developer
new
instantiations
That's actually the default - constructor functions aren't called for inline components. So AFAICT the instanceof
check would just need to be added here and here, and I just did a million instanceof
checks in under 3 milliseconds so I reckon we're okay on that front.
So I don't have any particular objection to this. Not that I've ever really understood the appeal of dropping new
- it means an extra function call, and is less idiomatic/explicit than the alternative. (Or, to paraphrase, 'get off my lawn!')
I'm ok with both :D
Disclaimer: I use components extensively (peppering <custom-element />
tags all over the place) and I don't see new Ractive({})
apart from the initial component insert call. :trollface:
Have created a PR (#1715) - any strong objections to it? (@dagnelies - it's optional, and the Ractive.extend()
case is covered, which hopefully addresses your concerns)
@Rich-Harris fine for me, it's your call! ;)
Hi....I am looking into Ractive.js and thank you for the great work. Just wondering if we can instantiate Ractive object in the following way?
It is to just add one line in the beginning of Ractive constructor like the following example.
I suggest this because I rarely use
new
to instantiate an object now. Use UpperCamelCase for class names is clear enough, and sometimes it can shorten the codes a lot in the following way:I assume it won't cause any issue, and apologized if I am wrong. :)