underscore's each checking for {} return of callback

前端 未结 1 1909

I was examining how UnderscoreJS implements their each/forEach

//somewhere up top:
var breaker = {};

//then the each function
var          


        
1条回答
  •  抹茶落季
    2020-12-03 22:03

    They use each internally for e.g. some. Since some does short-circuit, they can have each break there using the "secret" object, while not exposing this feature for regular users. They don't expose the break feature because the native function doesn't do that, either (so their shim is as native-like as possible). If they did, the break feature would only be available if the native function is unavailble, which isn't particularly helpful.

    0 讨论(0)
提交回复
热议问题