gpt4 book ai didi

javascript将参数传递给兄弟对象

转载 作者:行者123 更新时间:2023-11-30 07:26:52 26 4
gpt4 key购买 nike

我有这样的东西:

function showFunction () {
// need position and place
}

var obj = {
position: 1,
place: 2,
onShow: showFunction
}

如何从 showFunction 访问位置和地点?

最佳答案

this应该工作:

When a function is called as a method of an object, its this is set to the object the method is called on.

function showFunction() {
console.log(this.position, this.place);
}
var obj = {
position: 1,
place: 2,
onShow: showFunction
}
obj.onShow()

关于javascript将参数传递给兄弟对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11268530/

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