for..in 与 for..of的区别
for in
const arr = [,,2]
for(let i = 0; i < arr.length; i++){
if(i in arr){
// 不是稀疏项
console.log(arr[i]) // 2
}
}function Parent(){
this.say = 'hello'
}
//声明一个Peson类
function Person(){
this.name = "kaola";
this.age = 24;
this.func1 = function(){
}
}
Person.prototype = new Parent()
//实例化这个类
var bei = new Person();
//使用for-in遍历这个对象
for(keys in bei){
// name,age,func1,say
console.log(keys)
// true,true,true,false
console.log(bei.hasOwnProperty(keys))
}for of
最后更新于