简体   繁体   English

调用,绑定,应用Vs将引用对象作为参数传递

[英]Call, Bind, Apply Vs Passing The Reference Object As An Argument

Using call and bind is important when setting the value of this to the intended object. 在将this的值设置为预期对象时,使用调用和绑定很重要。 But what is the significance of using this instead of just passing the object as an argument to the function? 但是,使用this而不只是将对象作为参数传递给函数有什么意义?

The question occured to me after seeing that .bind is not supported in IE9 and below, so I started passing the object as a parameter to the function I am calling. 在看到IE9及以下版本不支持.bind之后,我想到了这个问题,所以我开始将对象作为参数传递给我正在调用的函数。 (I know I could use a shim for bind but that is not the question. The question is about the rationale behind using this .) (我知道我可以使用垫片进行bind但这不是问题。问题在于使用this的原理。)

What is the purpose of the this, call, apply, bind syntax in Javascript and what was it a solution to? Java中this, call, apply, bind语法的目的是什么,它的解决方案是什么? Wouldn't it be simpler to pass the object as a parameter both for cross-browser support and simplicity (since this is commonly misunderstood or forgotton to be set correctly in code)? 为跨浏览器支持和简化而将对象作为参数传递会不会更简单(因为this通常被误解或忘记了在代码中正确设置)?

As far as I know, this technique used at some languages (like Delphi). 据我所知,这种技术在某些语言(例如Delphi)中使用过。 But using one-argument-less is more convenient I guess. 但是我猜想少使用一个参数就更方便了。 It is not a functional style, it is OOP style and we love it, right? 它不是功能性样式,而是OOP样式,我们喜欢它,对吗? :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM