Allow constructor to be called without "new"
This commit is contained in:
parent
1ad0d91e57
commit
0d2b14e2bc
|
@ -129,7 +129,10 @@ Schema.prototype.define = function defineClass(className, properties, settings)
|
|||
standartize(properties, settings);
|
||||
|
||||
// every class can receive hash of data as optional param
|
||||
var newClass = function (data) {
|
||||
var newClass = function ModelConstructor(data) {
|
||||
if (!(this instanceof ModelConstructor)) {
|
||||
return new ModelConstructor(data);
|
||||
}
|
||||
AbstractClass.call(this, data);
|
||||
};
|
||||
|
||||
|
|
|
@ -108,7 +108,8 @@ function testOrm(schema) {
|
|||
it('should initialize object properly', function (test) {
|
||||
var hw = 'Hello word',
|
||||
now = Date.now(),
|
||||
post = new Post({title: hw});
|
||||
post = new Post({title: hw}),
|
||||
anotherPost = Post({title: 'Resig style constructor'});
|
||||
|
||||
test.equal(post.title, hw);
|
||||
test.ok(!post.propertyChanged('title'));
|
||||
|
@ -118,6 +119,8 @@ function testOrm(schema) {
|
|||
test.strictEqual(post.published, false);
|
||||
test.ok(post.date >= now);
|
||||
test.ok(post.isNewRecord());
|
||||
test.ok(anotherPost instanceof Post);
|
||||
test.ok(anotherPost.title, 'Resig style constructor');
|
||||
test.done();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue