The get in defineProperty in js is the same as the get in front of the method, right?

let obj1 = {}

Object.defineProperty(obj1,"name",{
    configurable:true,
    enumerable:true,
    get(){
        return "xxx"
    },
    set(val){

    }
})
getget
let obj2 = {
    get name(){
        return "xxx"
    },
    set name(val){

    }
}

Jun.08,2021

that's right, pretty much.

one is es5 syntax, the other is es6

Menu