문제

I needed to check an js object if is a function and i thought that this code should do it:

typeof param === 'function'

then i thought that checking with _.isFunction source code will be an good ideea.

Underscore has the if below wrapped arround the above check, which i'm not sure what exactly does or mean. If someone can explain this would be great. Thanks

// Optimize `isFunction` if appropriate.
if (typeof (/./) !== 'function') {
   ..
}
도움이 되었습니까?

해결책

In some old versions of V8, regular expressions objects had a type of "function" (initially, regular expressions objects were callable as functions, even if nobody used that feature).

That's why it wasn't possible to use typeof param === 'function' to check if a value is a function.

This isn't the case now. Use typeof, not _.isFunction, this code is obsolete.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top