Skip to content

Commit 03d14a0

Browse files
committed
Ensure initialize() still works in single instance mode
1 parent fa689c9 commit 03d14a0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/ParseObject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,13 +1473,13 @@ export default class ParseObject {
14731473
parentProto = classMap[adjustedClassName].prototype;
14741474
}
14751475
var ParseObjectSubclass = function(attributes, options) {
1476+
this.className = adjustedClassName;
1477+
this._objCount = objectCount++;
14761478
// Enable legacy initializers
14771479
if (typeof this.initialize === 'function') {
14781480
this.initialize.apply(this, arguments);
14791481
}
14801482

1481-
this.className = adjustedClassName;
1482-
this._objCount = objectCount++;
14831483
if (attributes && typeof attributes === 'object'){
14841484
if (!this.set(attributes || {}, options)) {
14851485
throw new Error('Can\'t create an invalid Parse Object');

src/__tests__/ParseObject-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,4 +2090,15 @@ describe('ParseObject extensions', () => {
20902090
f = new FeatureObject();
20912091
expect(f.foo() + f.bar()).toBe('FB');
20922092
});
2093+
2094+
it('can specify a custom initializer', () => {
2095+
var InitObject = ParseObject.extend('InitObject', {
2096+
initialize: function(attrs, options) {
2097+
this.set('field', 12);
2098+
}
2099+
});
2100+
2101+
var i = new InitObject()
2102+
expect(i.get('field')).toBe(12);
2103+
});
20932104
});

0 commit comments

Comments
 (0)