想参照老师的代码打一下,看看arugments,结果提示SyntaxError: Unexpected token this,跪求解决

来源:6-4 [JavaScript]函数属性arguments

风魔大王

2016-11-29 10:59

function foo(){
  this.b=100;
  retrun this.a;
}
var func=foo.binddd({a:1});
Function.prototype.binddd=function(oThis){
  var aArgs=Array.prototype.slice.call(arguments,1);
  fToBind=this;
  fNOP=function(){};
  Bound=function(){
    return fToBind.apply(this instanceof fNOP?this:oThis,aArgs.concat(Array.prototype.slice.call(arguments)));
  }
  fNOP.prototype=this.prototype;
  fBound.prototype=new fNOP();
  return fBound;
};
func();
new func();


写回答 关注

1回答

  • vowless
    2016-11-30 11:50:09
    已采纳
    function foo(){
      this.b=100;
      return this.a;
      //retrun打错了
    }
    var func=foo.bind({a:1});
    //binddd打错了
    Function.prototype.bind=function(oThis){
      //binddd打错了
      var aArgs=Array.prototype.slice.call(arguments,1);
      fToBind=this;
      fNOP=function(){};
      Bound=function(){
        return fToBind.apply(this instanceof fNOP?this:oThis,aArgs.concat(Array.prototype.slice.call(arguments)));
      }
      fNOP.prototype=this.prototype;
      fBound.prototype=new fNOP();
      return fBound;
    };
    console.log(func());//->1
    console.log(new func())//->[object Object] {b: 100}(bind失效,忽略return,直接返回this{b=100}的对象)


    慕移动411... 回复风魔大王

    我去,好的浏览器使用了兼容binddd的吗?那是不是可以写functionnn,thisss,forrr,ifff了!

    2018-10-13 11:05:09

    共 3 条回复 >

JavaScript深入浅出

由浅入深学习JS语言特性,且解析JS常见误区,从入门到掌握

281097 学习 · 1020 问题

查看课程

相似问题