gpt4 book ai didi

javascript - 从javascript中的对象方法访问对象属性

转载 作者:行者123 更新时间:2023-11-30 08:13:13 25 4
gpt4 key购买 nike

我有类似的东西

var foo = function(arg){
var something = {
myPropVal: "the code",
myMethodProp: function(bla) {
// do stuff with mypropval here
alert(this) // => DOMWindow
}
}
}

这可能吗?我可以从 myMethodProp 中访问 myPropVal 的内容吗?

最佳答案

当然可以

var foo = function(arg){
var something = {
myPropVal: "the code",
myMethodProp: function(bla) {
// do stuff with mypropval here
alert(this) // => DOMWindow
alert(this.myPropVal);
}
}

alert(something.myMethodProp());
}
foo();

关于javascript - 从javascript中的对象方法访问对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7484698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com