javascript - 使函数使用对象作为其作用域
问题描述
假设我有这样的代码:
var opts = {hello: "it's me", imusthavetried: "a thousand times"}
function myFunction (options) {
}
myFunction(opts)
有什么办法可以让它myFunction
只写hello
而不是options.hello
?我知道我可以遍历每个选项对象子对象并重新定义它们,但是有没有办法自动将选项对象用作函数的范围?
解决方案
推荐阅读
- javascript - Javascript新手
- ios - 在可访问性模式下将文本设置为更大后,iOS 应用程序冻结
- python - 从另一个文件调用python函数
- java - 是否可以在运行时向拓扑中添加新的状态存储
- git - 如何删除合并的提交日志?
- swift - 尝试呈现
上 其视图不在窗口层次结构中 - java - 分配给新多维数组的数据不断更新
- sqlite - 我们可以在没有 sqlite 触发器递归的情况下在 sqlite 触发器中使用 for/while 循环吗?
- ruby-on-rails - 无法使用 Ruby Gems(Ruby on Rails 应用程序)在生产中抓取链接的配置文件
- flutter - 真实设备上的颤振在第二次单击(触摸)后开始工作