Javascript 从对象获取属性

Javascript 从对象获取属性,javascript,Javascript,我有一个目标: this.utils = { width: 200, doSomeWorkWithWidth: function(){ // How to access width property from inside this code? console.log(width) } } 我需要从外部更改width属性,然后从函数内部对其值执行一些操作。如何以正确的方式从该功能访问它 另一件事是,我将在其他更复杂的代码中使用utils对

我有一个目标:

this.utils = {
    width: 200,
    doSomeWorkWithWidth: function(){
        // How to access width property from inside this code?
        console.log(width)
    }
}
我需要从外部更改width属性,然后从函数内部对其值执行一些操作。如何以正确的方式从该功能访问它


另一件事是,我将在其他更复杂的代码中使用
utils
对象,其中
将分配给另一个对象,因此
此.width
似乎不起作用。

您使用

var utils = {
    width: 200,
    doSomeWorkWithWidth: function(){
        // How to access width property from inside this code?
        console.log(this.width)
    }
}

使用
this
utils.width

var utils={
宽度:200,
doSomeWorkWithWidth:function(){
//如何从代码内部访问width属性?
console.log(这个.width);
//或
console.log(utils.width);
}
}

utils.doSomeWorkWithWidth()使用console.log(this.width)@Sergei Basharov你怎么称呼doSomeWorkWithWidth?