JavaScript 函数在对象中执行
我想向某个对象添加一个函数(以变量的形式)并在我需要时执行它。
如何做到这一点?
谢谢。
I want to add a function to some object (in a form of a variable) and execute it when i need too.
How to do this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不会影响 obj 的任何现有字段或方法(明显的例外是如果已经存在
doSomething
)。This won't affect any of obj's existing fields or methods (the obvious exception being if there's already a
doSomething
).如果需要,您还可以跳过
myFunc
临时变量。You can also skip the
myFunc
temporary variable if you want to.相当模糊,但你可以看一下:
Pretty vague, but here you go: