Function.prototype.bind = function() {
var _this = this,
original = _this,
args = Array.prototype.slice.call(arguments),
_obj = args.shift(),
func = function() {
var _that = _obj;
return original.apply(_that, args.concat(
Array.prototype.slice.call(
arguments, args.length)));
};
func.bind = function() {
var args = Array.prototype.slice.call(arguments);
return Function.prototype.bind.apply(_this, args);
}
return func;
};
나는 그것이 bind 함수라는 것을 알고있다. 그러나 나는 그것이 무엇을하고 있는지, 특히 args.concat
부분을 이해하지 못합니다. concat
의 기능은 무엇입니까? 또한 .bind
메서드는 무엇을합니까 .apply
및 .call
할 수 없습니까?이 코드는 어떤 기능을합니까?
'bind'는 함수를 호출하고,'call'과'apply'는 함수를 호출합니다. 그들은 다른 짐승입니다. 'bind'는 나중에 사용될 함수가 함수에 대한 인자를 바인딩하는 옵션과 함께 특정 컨텍스트와 함께 호출되도록하려는 경우에 사용됩니다. –