2 回答

TA贡献1783条经验 获得超4个赞
首先创建空对象
它不是在创建 null对象,而是在创建对象,null并将其作为原型检查Object.create文档:
var duplicateTagsGuard = Object.create(null);
console.log(`duplicateTagsGuard is an empty object:`);
console.log(duplicateTagsGuard);
console.log(`Prototye of duplicateTagsGuard is null: `);
console.log(Object.getPrototypeOf(duplicateTagsGuard));
对其循环进行迭代,并声明变量val,使其等于标签数组中的每个元素
这部分是正确的每次循环运行一个新的变量与创建的块范围和分配的电流的值co第所述的索引值tags数组。
然后检查该val是否在duplicateTagsGuard对象中,并且是否使用return语句来防止继续进行循环,如果不是,则我们将val的值添加到对象中,但是我不知道如何用那部分代码实现它( repeatTagsGuard [val] = true)
它正在检查对象val的属性是否duplicateTagsGuard存在,如果已经存在,则使用return返回响应,否则它将duplicateTagsGuard使用括号符号 将该属性添加到对象中,[propertyName]并将其值分配为true。
var duplicateTagsGuard = Object.create(null); //creating a new empty object with prototype as null
let val = "hello"; //creating a new variable
duplicateTagsGuard[val] = true; //adding the property with the value of the variable val
console.log(val in duplicateTagsGuard); //checking if the added property is present in the object
添加回答
举报