[英]i have an javascript function that not working
function filter_effect(effect_name){
var tmp_img = document.createElement("IMG");
tmp_img.src = get_cropped_image()
tmp_img.style.display = "none"
Caman(tmp_img, function (){
this[effect_name]();
this.render(function () {
change_picture(this.canvas.toDataURL("image/jpeg"))
});
});
}
this is my code and when I run this I get this error这是我的代码,当我运行它时,我收到此错误
Uncaught TypeError: this[effect_name] is not a function
未捕获的类型错误:this[effect_name] 不是函数
Can anyone help that what I should do to fix this?任何人都可以帮助我应该做些什么来解决这个问题?
You should change your function call and pass the this
.您应该更改函数调用并传递
this
。 Change this line, it would be solved:改变这一行,它会解决:
Caman.call(this, tmp_img, function (){
/* Your callback function body */
});
Here this
means the filter_effect
function.下面
this
意味着filter_effect
功能。 When you want to change the this
object in function calls, you have to use .apply() or .call() to change it.当你想在函数调用中改变
this
对象时,你必须使用 .apply() 或 .call() 来改变它。
您必须澄清“this”引用值,它必须是指一个 javascript 对象,其 effect_name 属性被声明为函数,使用浏览器的调试器对其值进行审查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.