perf(core): be more consistent about typeof checks (#28400)
When testing whether `value` is an object, use the ideal sequence of strictly not equal to `null` followed by `typeof value === 'object'` consistently. Specifically there's no point in using double equal with `null` since `undefined` is ruled out by the `typeof` check. Also avoid the unnecessary ToBoolean check on `value.ngOnDestroy` in `hasOnDestroy()`, since the `typeof value.ngOnDestroy === 'function'` will only let closures pass and all closures are truish (with the notable exception of `document.all`, but that shouldn't be relevant for the `ngOnDestroy` hook). PR Close #28400
This commit is contained in:

committed by
Jason Aden

parent
2bb518c694
commit
9af18c2fd0
@ -248,7 +248,7 @@ export class NodeInjectorFactory {
|
||||
const FactoryPrototype = NodeInjectorFactory.prototype;
|
||||
export function isFactory(obj: any): obj is NodeInjectorFactory {
|
||||
// See: https://jsperf.com/instanceof-vs-getprototypeof
|
||||
return obj != null && typeof obj == 'object' && Object.getPrototypeOf(obj) == FactoryPrototype;
|
||||
return obj !== null && typeof obj == 'object' && Object.getPrototypeOf(obj) == FactoryPrototype;
|
||||
}
|
||||
|
||||
// Note: This hack is necessary so we don't erroneously get a circular dependency
|
||||
|
Reference in New Issue
Block a user