Skip to content

Commit abe5a53

Browse files
committed
Merge pull request #81 from TylerBrock/move-initialize
Move invocation of initialize above setting of attributes and validation
2 parents 5e86f78 + 648a59f commit abe5a53

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/ParseObject.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ export default class ParseObject {
9999
className: string;
100100

101101
constructor(className: ?string | { className: string, [attr: string]: mixed }, attributes?: { [attr: string]: mixed }, options?: { ignoreValidation: boolean }) {
102+
// Enable legacy initializers
103+
if (typeof this.initialize === 'function') {
104+
this.initialize.apply(this, arguments);
105+
}
106+
102107
var toSet = null;
103108
this._objCount = objectCount++;
104109
if (typeof className === 'string') {
@@ -121,10 +126,6 @@ export default class ParseObject {
121126
if (toSet && !this.set(toSet, options)) {
122127
throw new Error('Can\'t create an invalid Parse Object');
123128
}
124-
// Enable legacy initializers
125-
if (typeof this.initialize === 'function') {
126-
this.initialize.apply(this, arguments);
127-
}
128129
}
129130

130131
/** Prototype getters / setters **/
@@ -1371,17 +1372,18 @@ export default class ParseObject {
13711372
parentProto = classMap[adjustedClassName].prototype;
13721373
}
13731374
var ParseObjectSubclass = function(attributes, options) {
1375+
// Enable legacy initializers
1376+
if (typeof this.initialize === 'function') {
1377+
this.initialize.apply(this, arguments);
1378+
}
1379+
13741380
this.className = adjustedClassName;
13751381
this._objCount = objectCount++;
13761382
if (attributes && typeof attributes === 'object'){
13771383
if (!this.set(attributes || {}, options)) {
13781384
throw new Error('Can\'t create an invalid Parse Object');
13791385
}
13801386
}
1381-
// Enable legacy initializers
1382-
if (typeof this.initialize === 'function') {
1383-
this.initialize.apply(this, arguments);
1384-
}
13851387
};
13861388
ParseObjectSubclass.className = adjustedClassName;
13871389
ParseObjectSubclass.__super__ = parentProto;

0 commit comments

Comments
 (0)