@@ -1959,37 +1959,60 @@ class ParseObject {
1959
1959
let parentProto = ParseObject . prototype ;
1960
1960
if ( this . hasOwnProperty ( '__super__' ) && this . __super__ ) {
1961
1961
parentProto = this . prototype ;
1962
- } else if ( classMap [ adjustedClassName ] ) {
1963
- parentProto = classMap [ adjustedClassName ] . prototype ;
1964
1962
}
1965
- const ParseObjectSubclass = function ( attributes , options ) {
1963
+ let ParseObjectSubclass = function ( attributes , options ) {
1966
1964
this . className = adjustedClassName ;
1967
1965
this . _objCount = objectCount ++ ;
1968
1966
// Enable legacy initializers
1969
1967
if ( typeof this . initialize === 'function' ) {
1970
1968
this . initialize . apply ( this , arguments ) ;
1971
1969
}
1972
1970
1971
+ if ( this . _initializers ) {
1972
+ for ( const initializer of this . _initializers ) {
1973
+ initializer . apply ( this , arguments ) ;
1974
+ }
1975
+ }
1976
+
1973
1977
if ( attributes && typeof attributes === 'object' ) {
1974
1978
if ( ! this . set ( attributes || { } , options ) ) {
1975
1979
throw new Error ( "Can't create an invalid Parse Object" ) ;
1976
1980
}
1977
1981
}
1978
1982
} ;
1979
- ParseObjectSubclass . className = adjustedClassName ;
1980
- ParseObjectSubclass . __super__ = parentProto ;
1981
-
1982
- ParseObjectSubclass . prototype = Object . create ( parentProto , {
1983
- constructor : {
1984
- value : ParseObjectSubclass ,
1985
- enumerable : false ,
1986
- writable : true ,
1987
- configurable : true ,
1988
- } ,
1989
- } ) ;
1983
+ if ( classMap [ adjustedClassName ] ) {
1984
+ ParseObjectSubclass = classMap [ adjustedClassName ] ;
1985
+ } else {
1986
+ ParseObjectSubclass . extend = function ( name , protoProps , classProps ) {
1987
+ if ( typeof name === 'string' ) {
1988
+ return ParseObject . extend . call ( ParseObjectSubclass , name , protoProps , classProps ) ;
1989
+ }
1990
+ return ParseObject . extend . call ( ParseObjectSubclass , adjustedClassName , name , protoProps ) ;
1991
+ } ;
1992
+ ParseObjectSubclass . createWithoutData = ParseObject . createWithoutData ;
1993
+ ParseObjectSubclass . className = adjustedClassName ;
1994
+ ParseObjectSubclass . __super__ = parentProto ;
1995
+ ParseObjectSubclass . prototype = Object . create ( parentProto , {
1996
+ constructor : {
1997
+ value : ParseObjectSubclass ,
1998
+ enumerable : false ,
1999
+ writable : true ,
2000
+ configurable : true ,
2001
+ } ,
2002
+ } ) ;
2003
+ }
1990
2004
1991
2005
if ( protoProps ) {
1992
2006
for ( const prop in protoProps ) {
2007
+ if ( prop === 'initialize' ) {
2008
+ Object . defineProperty ( ParseObjectSubclass . prototype , '_initializers' , {
2009
+ value : [ ...( ParseObjectSubclass . prototype . _initializers || [ ] ) , protoProps [ prop ] ] ,
2010
+ enumerable : false ,
2011
+ writable : true ,
2012
+ configurable : true ,
2013
+ } ) ;
2014
+ continue ;
2015
+ }
1993
2016
if ( prop !== 'className' ) {
1994
2017
Object . defineProperty ( ParseObjectSubclass . prototype , prop , {
1995
2018
value : protoProps [ prop ] ,
@@ -2013,15 +2036,6 @@ class ParseObject {
2013
2036
}
2014
2037
}
2015
2038
}
2016
-
2017
- ParseObjectSubclass . extend = function ( name , protoProps , classProps ) {
2018
- if ( typeof name === 'string' ) {
2019
- return ParseObject . extend . call ( ParseObjectSubclass , name , protoProps , classProps ) ;
2020
- }
2021
- return ParseObject . extend . call ( ParseObjectSubclass , adjustedClassName , name , protoProps ) ;
2022
- } ;
2023
- ParseObjectSubclass . createWithoutData = ParseObject . createWithoutData ;
2024
-
2025
2039
classMap [ adjustedClassName ] = ParseObjectSubclass ;
2026
2040
return ParseObjectSubclass ;
2027
2041
}
0 commit comments