this question에서 나는 생성자를 사용할 제안을 보지 못했습니다.JavaScript에서 type을 감지하기위한 생성자와 typeof 비교
그래서 그 대신 typeof callback == "function"
의 나는 callback && (callback.constructor==Function)
를 사용합니다.
나에게 그것은 메모리 포인터와의 비교가 런타임 성능과 코딩 안전면에서 문자열 비교보다 항상 더 낫다는 것이 확실합니다.
모든 유형을 감지하고 못생긴 것을 잊어 버리는데 왜 생성자를 사용하지 않습니까? typeof
?
그것은 모든 원시 형, 함수 및 배열에 대한 작동합니다
undefined === undefined
null === null
[1,2,3].constructor == Array
(1).constructor == Number
(true).constructor == Boolean
(()=>null).constructor == Function
'abc'.constructor == String
(new Date()).constructor == Date
else it's an object, where instanceof helps to detect it's parents if needed.
string interning 경우는 다음 런타임 성능 이점이 사라질에 의존 할 수있다. 그러나 안전한 코딩 이점은 여전히 유지됩니다.
은'function'와'function' 비교? – Rayon