Skip to content

Instantly share code, notes, and snippets.

@kushdilip
Last active March 5, 2019 08:31
Show Gist options
  • Save kushdilip/be48745d7b18734a2b5e156af82c751d to your computer and use it in GitHub Desktop.
Save kushdilip/be48745d7b18734a2b5e156af82c751d to your computer and use it in GitHub Desktop.
Ember Source Code Reading
// `window.ActiveXObject` is "falsey" in IE11 (but not `undefined` or `false`)
// `"ActiveXObject" in window` returns `true` in all IE versions
// only IE11 will pass _both_ of these conditions
declare global {
interface Window {
ActiveXObject: any;
}
}
export const isIE11 = !window.ActiveXObject && 'ActiveXObject' in window;
export const isEdge = /Edge/.test(navigator.userAgent);
let isNode =
typeof window === 'undefined' &&
typeof process !== 'undefined' &&
{}.toString.call(process) === '[object process]';
// I have made an attempt to go through ember.js source code.
// Below snippets are taken from the same which do specific tasks.
// Creates object with no constructor
let empty1 = Object.create(null);
// Outputs: undefined
console.log(empty2.constructor)
let empty2 = {};
// Outputs: ƒ Object() { [native code] }
console.log(empty2.constructor)
/*
* Reference Link
* http://adripofjavascript.com/blog/drips/creating-objects-without-prototypes.html
*/
// check if window exists and actually is the global
export default typeof self === 'object' &&
self !== null &&
(self as any).Object === Object &&
typeof Window !== 'undefined' &&
self.constructor === Window &&
typeof document === 'object' &&
document !== null &&
self.document === document &&
typeof location === 'object' &&
location !== null &&
self.location === location &&
typeof history === 'object' &&
history !== null &&
self.history === history &&
typeof navigator === 'object' &&
navigator !== null &&
self.navigator === navigator &&
typeof navigator.userAgent === 'string';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment