Slightly improve instantiateProps

This commit is contained in:
pandamicro
2016-07-22 16:52:42 +08:00
parent 69b6032686
commit 786aae553e
+13 -15
View File
@@ -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;
}