這幾天在閱讀underscore的源碼,看到函數(shù)方法的時候,遇到一點問題。請大家,幫個忙啦~underscore1.7bind函數(shù)源碼javascript_.bind=function(func,context){varargs,bound;if(nativeBind&&func.bind===nativeBind)returnnativeBind.apply(func,slice.call(arguments,1));if(!_.isFunction(func))thrownewTypeError('Bindmustbecalledonafunction');args=slice.call(arguments,2);bound=function(){if(!(thisinstanceofbound))returnfunc.apply(context,args.concat(slice.call(arguments)));Ctor.prototype=func.prototype;varself=newCtor;Ctor.prototype=null;varresult=func.apply(self,args.concat(slice.call(arguments)));if(_.isObject(result))returnresult;returnself;};returnbound;};問題實際使用時,哪一種情況會跳過下面的if判斷,執(zhí)行后面的代碼?能否舉個實例?javascriptif(!(thisinstanceofbound))returnfunc.apply(context,args.concat(slice.call(arguments)));
underscore 1.7 _.bind函數(shù)源碼疑惑
海綿寶寶撒
2019-04-07 11:18:26