a.方式1
let obj1 = {
name: "lwj",
say: function() {
console.log("abc");
}
};
let obj2 = {};
let str1 = JSON.stringify(obj1);
let str2 = JSON.stringify(obj2);
console.log(str1);
console.log(str2);
console.log(str2 === "{}");
b.方式2
let obj1 = {
name: "lwj",
say: function() {
console.log("abc");
}
};
let obj2 = {};
// getOwnPropertyNames 获取指定对象所有的属性
let keys1 = Object.getOwnPropertyNames(obj1);
let keys2 = Object.getOwnPropertyNames(obj2);
console.log(keys1);
console.log(keys2);
console.log(keys2.length === 0);
c.方式3
let obj1 = {
name: "lwj",
say: function() {
console.log("abc");
}
};
let obj2 = {};
let keys1 = Object.keys(obj1);
let keys2 = Object.keys(obj2);
console.log(keys1);
console.log(keys2);
console.log(keys2.length === 0);