如何将```this`''绑在函数参数中

发布于 2025-02-12 06:12:22 字数 860 浏览 0 评论 0原文

我有搜索并尝试了一些方法,例如直接使用app.shadow.dialogue({...}。bind(this)),但得到此错误

untuff typeError:{(中间值)(中间值)}。bind不是函数

,而是尝试执行此操作,

let dialogue = {
  "title": {
    "text": "Kembali ke tes?",
    "description": "Anda memiliki tes yang masih berlangsung"
  },
  "actions": [
    {
      "text": "Ya",
      "class": "bg-safe",
      "icon": "refresh",
      "action": "direct/tes"
    },{
      "text": "Tidak, Lihat Hasil Sebelumnya",
      "class": "bg-danger",
      "icon": "close",
      "action": function() {
        app.shadow.stop();
        this.view();
      }
    }
  ]
};

dialogue.actions[1].action.bind(this);
app.shadow.dialogue(dialogue);

而是this.view仍然没有进入范围

uck typeerror:this.view不是函数

有没有一种方法可以使语句在对象参数中可用?

I have search and try few method, like directly using app.shadow.dialogue({...}.bind(this)) but getting this error

Uncaught TypeError: {(intermediate value)(intermediate value)}.bind is not a function

And trying to do this instead

let dialogue = {
  "title": {
    "text": "Kembali ke tes?",
    "description": "Anda memiliki tes yang masih berlangsung"
  },
  "actions": [
    {
      "text": "Ya",
      "class": "bg-safe",
      "icon": "refresh",
      "action": "direct/tes"
    },{
      "text": "Tidak, Lihat Hasil Sebelumnya",
      "class": "bg-danger",
      "icon": "close",
      "action": function() {
        app.shadow.stop();
        this.view();
      }
    }
  ]
};

dialogue.actions[1].action.bind(this);
app.shadow.dialogue(dialogue);

but this.view still not get into scope

Uncaught TypeError: this.view is not a function

Is there a way to make this statement useable inside an object argument?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

錯遇了你 2025-02-19 06:12:25

也许您可以尝试:

`
"action":()=> {
        app.shadow.stop();
        this.view();
      }`

希望这对您有用。

may be you can try :

`
"action":()=> {
        app.shadow.stop();
        this.view();
      }`

hope this is useful for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文