我写了这段代码,它很简单,我有一个空对象,它将包含一些其他对象作为属性,但该对象保持空白并且不添加所需的属性..将属性添加到对象
let buildProfileClientValidator = function(form , rules){
let elements = {};
function init(){
//Some code that works fine
addElement(elementName , elementType);
addElement(elementName , elementType);
//the elements object should now have some other objects as properties
//but it`s empty !!!!
console.log(elements);
}
function addElement(elementName , elementType){
//this condition works fine
if(!elementExist(elementName)){
//console.log(elementName , elementType); also works fine -> the values of elementName , elementType are present
elements[elementName] = {
type : elementType,
value : '',
rules : (rules[elementName] == undefined) ? '' : rules[elementName].split('|')
};
}
}
}
所以我错过了什么?!
请向我们展示您的实际代码,包括'elementExist'函数。 –
@ScottMarcus https://gist.github.com/anonymous/0ec45b639313cdeb14f3 –
在我浏览你的代码之前,你能告诉我为什么你在使用let?你这样做是因为还是你有特殊原因? –