Let me start off by saying that I've only been working with canJS for about 2 weeks. I'm new, but i came across something that caused me a few hours of frustration and I thought could be improved to help future users.
The issue was that can.Observe objects must be instantiated with the new keyword.
This is fine, except that all other canJS object builders do not require use of the 'new' keyword, as they return constructor functions.- var observer = new can.Observe( datasource );
- var Todo = can.Model(...);
- var t = new Todo(...)
There is nothing wrong with all this, except that it's a bit inconsistent. Almost all 'can.' namespace functions are used without the 'new' keyword, except for can.Observe. It's easy to forget to use 'new' and spend hours figuring out why your data object isn't working.
I'm not sure if a self invoking constructor could be implemented, but i personally think it would be helpful.
- if (!(this instanceof can.Observe)) {
- return new can.Observe(datasource);
- }