[英]JS: bind function fail passing arguments in recursions
例如:
function GoAlert(text){
alert(text)
setTimeout(GoAlert.bind(text),100);
}
GoAlert("Hello World");
第一个警报显示“ Hello World
,但下一个警报显示“ undefined
。 为什么?
当使用.bind()
您所提供的第一个参数指定的值, this
对于功能。
句法
fun .bind( thisArg [, arg1 [, arg2 [, ...]]])
要为第一个参数( text
)提供一个值,它应该是第二个参数( arg1
)。
setTimeout(GoAlert.bind(undefined, text), 100);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.