-
getOwnPropertySymbols
獲取對象中所有Symbol類型的key
const a = Symbol('a'); let obj = {}; obj[a] == 11; Object.getOwnPropertySymbols(a); > Symbol(a)
-
getOwnPropertyNames
返回一個由指定對象的所有自身屬性的屬性名(包括不可枚舉屬性但不包括Symbol值作為名稱的屬性)組成的數組
let scc= {age:11} Object.getOwnPropertyNames(scc) > ["age"]
-
Object.defineProperty(obj, prop, descriptor)
在對象上定義屬性,并描述屬性的狀態,比如
configurable: false, writable: true, enumerable: true, value: '張三'
let a= {}; Object.defineProperty(a,age,{ writable:false,//是否可以被改寫,不會報錯。 enumerable:false,//是否可以被枚舉 configurable:true,//是否可以被刪除 value:22//屬性的值, get:func,//取值時會觸發 set:func//設置值時會觸發 })
-
Object.defineProperties
與上面的區別就是,第二個參數同時定義屬性名,和描述
Object.defineProperties(obj, { name: { value: '張三', configurable: false, writable: true, enumerable: true }, age: { value: 18, configurable: true } })
-
Object.preventExtensions(obj);
設置對象為不能擴展,即不能添加新屬性.
-
Object.isExtensible(obj);
設置對象為可以擴展,即是上面的取反。
-
obj.hasOwnProperty(prop)
判斷對象是否擁有該屬性
let a = { age:11 }; a.hasOwnProperty('age') > true
-
Object.getOwnPropertyDescriptors
返回對象的所有的屬性的描述
let a = {age:1} Object.getOwnPropertyDescriptors(a);
-
Object.getOwnPropertyDescriptor
獲取對象指定的屬性的描述
let a = {age:1} Object.getOwnPropertyDescriptor(a,'age');
-
Object.getPrototypeOf(a)
獲取對象的原型
-
isPrototypeOf
獲取后面的那個是不是在前面那個的原型鏈上
let a =function(){} let b = new a(); a.prototype.isPrototypeOf(b); > true
-
Object.setPrototypeOf(a,{age:11})
設置對象的proto,想當于,a.proto = {age:11}
-
Object.getPrototypeOf(a)
獲取對象的proto
后面還會補充....