mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Slightly improve instantiateProps
This commit is contained in:
@@ -291,24 +291,22 @@ function instantiateProps (instance, itsClass) {
|
||||
for (var i = 0; i < propList.length; i++) {
|
||||
var prop = propList[i];
|
||||
var attrKey = prop + DELIMETER + 'default';
|
||||
if (attrKey in attrs) { // getter does not have default
|
||||
var def = attrs[attrKey];
|
||||
var def = attrs[attrKey];
|
||||
if (def !== undefined) { // getter does not have default
|
||||
// default maybe 0
|
||||
if (def) {
|
||||
if (typeof def === 'object' && def) {
|
||||
if (typeof def.clone === 'function') {
|
||||
def = def.clone();
|
||||
}
|
||||
else if (Array.isArray(def)) {
|
||||
def = [];
|
||||
}
|
||||
else {
|
||||
def = {};
|
||||
}
|
||||
if (typeof def === 'object' && def) {
|
||||
if (typeof def.clone === 'function') {
|
||||
def = def.clone();
|
||||
}
|
||||
else if (typeof def === 'function') {
|
||||
def = getDefault(def);
|
||||
else if (Array.isArray(def)) {
|
||||
def = [];
|
||||
}
|
||||
else {
|
||||
def = {};
|
||||
}
|
||||
}
|
||||
else if (typeof def === 'function') {
|
||||
def = getDefault(def);
|
||||
}
|
||||
instance[prop] = def;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user