Your 'this' doesn't reference to window, causing errors in strict environment.
indigo-sam opened this issue · 3 comments
(function (root, factory) {
if (typeof define === "function" && define.amd) {
// AMD - registered as an anonymous module
define(factory);
} else if (typeof exports === "object") {
// CommonJS
module.exports = factory();
} else {
// Browser global
root.objectFitPolyfill = factory();
}
})(this, function () {... //'this' in a strict environment would reference to 'undefined' thus creating an undefined error.
Could you please confirm (and preferably take screenshots) of any errors being thrown?
The above code is a very common Universal Module Definition pattern for Javascript modules. I would strongly prefer not to change a pattern that isn't mine, since this
changes depending on whether the environment is the browser, Node, etc (more info in this Stackoverflow discussion and also this article).
Oh that would make sense if they use the plugin in Node to reference different object. I was using babel and it automatically add a global 'use strict'. The 'this' would be forced to be an undefined instead of window object, but I see why it should be 'this' instead of window now. I guess I have to use different babel preset plugin to turn off global 'use strict'.
Thanks Sam! Looks like if you're using Babel 6, you can just not include the strict-mode
plugin. This Stackoverflow question might help? :)