我如何在this.function.bind(this)中替换任何数值作为参数
How can I substitute any numeric value for argument in this.function.bind(this)
class hoge{
constructor(key) {
this.Idx = require("./myIndex.json");
}
foo(id, concepts){
var aFunction = {
"one": this.selectAction.bind(this),
"two": this.selectAction.bind(this)
}
selectAction(id, concepts, number){
return (id + concepts + this.Idx[number])
}
}
我如何在this. selectaction .bind(this)中的函数方法中替换任何数值仅为number的一个参数?例如,"一":this.selectAction。Bind (this, number = 0);"两个":this.selectAction。Bind (this, number = 1);
如果我这样写,返回这个错误
ReferenceError: number is not defined
根据bind文档,你必须按顺序传递参数。
class hoge{
constructor(key) {
this.Idx = require("./myIndex.json");
}
foo(id, concepts){
var aFunction = {
one: this.selectAction.bind(this, id, concepts, 1),
two: this.selectAction.bind(this, id, concepts, 2)
}
selectAction(id, concepts, number){
return (id + concepts + this.Idx[number])
}
}
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 我如何找到一个句子中的所有空格并替换忽略它们
- $(this).prop('property') vs. this.property
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 如何用更合适的内容替换document.write
- 是否有任何方法可以使用jQuery替换在数组中定义值的文本
- 在DOM中查找一个模式并替换它's的内容使用jquery
- 用空格替换下划线PHP
- str.split(someString).join(someOtherString)是否等效于替换
- 在另一个函数中使用变量this
- this.router在AngularJS 2中未定义
- 使用javascript的图像替换循环
- window.location替换并传递URL历史记录条目中的变量
- 如何仅替换一些“this”外部函数
- 为什么不't this replace()替换"我的“;
- 使用let初始化的函数在被this访问时不被替换
- Javascript/jsLint:使用“use strict”时用什么替换jQuery(this);
- 我如何在this.function.bind(this)中替换任何数值作为参数
- 使用Jquery和$(this).text()来替换文本
- 你能用this.queryText.replace替换两个不同的文本吗?