polyfills

RequireJS: Conditionally Load Polyfill Using Modernizr

孤人 提交于 2019-12-04 21:53:25
How do you wrap a polyfill script as an AMD module and conditionally load it using Modernizr and RequireJS? (Figured it out while I was drafting my question - posting answer for anyone else trying to do the same thing.) The polyfill I needed to load was jquery-placeholder for browsers that don't support input placeholders. It does not provide AMD support out of the box. First I wrapped it as an AMD module like this: define(['jquery'], function ($) { (function(window, document, $) { ... polyfill ... }(this, document, jQuery)); }); Then in main.js I used Modernizr to conditionally require() the

Angular2 Typescript app throws 404 on components when js extension not specified

梦想的初衷 提交于 2019-12-04 15:39:06
问题 I just started to play around with Angular2, and ran into a weird component file extension problem: Let's use the 5 minutes quickstart demo from angular.io (I'll reproduce the code here for reference). File structure angular2-quickstart |- app | |- app.component.ts | |- boot.ts | |- index.html |- package.json |- tsconfig.json package.json { "name": "angular2-quickstart", "version": "1.0.0", "scripts": { "tsc": "tsc", "tsc:w": "tsc -w", "lite": "lite-server", "start": "concurrent \"npm run tsc

Babel polyfill with webpack

梦想与她 提交于 2019-12-04 09:22:06
Do I need to include import "babel-polyfill" to the top of each entry file, or is it enough to have babel-polyfill rule just in webpack.config file? I am confused by polyfill docs and still getting following error: only one instance of babel-polyfill is allowed My webpack.config in short: entry1: ['babel-polyfill', 'homepage.js'], entry2: ['babel-polyfill', 'not-homepage.js'], entry3: ['babel-polyfill', 'contacts.js'] You are getting the error because you are calling multiple instances of the babel-polyfill. You can choose any of the two option, but not both. If you use webpack, don't put

How do you add polyfills to Globals in typescript (modules)

倾然丶 夕夏残阳落幕 提交于 2019-12-04 03:16:57
问题 I was able to find a polyfill(on stack overflow) for Array#includes and add it to typescript but after adding a small import to my file it turned into a module(I understand why they do this for export, but why on import) and I couldn't modify the global namespace anymore. How do I fix the polyfill? interface Array<T> { includes(searchElement: T) : boolean; } // Add Array includes polyfill if needed // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

Comparing a variable with itself

北慕城南 提交于 2019-12-04 01:00:01
问题 I stumbled over this polyfill of Array.prototype.includes. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes. Is there a reason for the comparison of the variables with themselves on line 21,22? if (searchElement === currentElement || (searchElement !== searchElement && currentElement !== currentElement)) { return true; } 回答1: Yes, this second operand of the || does check whether both searchElement and currentElement are NaN - the only value in

Array Reduce Polyfill Explanation

雨燕双飞 提交于 2019-12-03 20:21:16
Apologize in advance for lengthy post. I am trying to understand array reduce polyfill provided by MDN. I could not understand some lines in the polyfill can you explain it please. Below is the code if (!Array.prototype.reduce) { Object.defineProperty(Array.prototype, 'reduce', { value: function(callback /*, initialValue*/) { if (this === null) { throw new TypeError( 'Array.prototype.reduce ' + 'called on null or undefined' ); } if (typeof callback !== 'function') { throw new TypeError( callback + ' is not a function'); } // 1. Let O be ? ToObject(this value). var o = Object(this); // 2. Let

Angular2 Typescript app throws 404 on components when js extension not specified

て烟熏妆下的殇ゞ 提交于 2019-12-03 09:43:22
I just started to play around with Angular2, and ran into a weird component file extension problem: Let's use the 5 minutes quickstart demo from angular.io (I'll reproduce the code here for reference). File structure angular2-quickstart |- app | |- app.component.ts | |- boot.ts | |- index.html |- package.json |- tsconfig.json package.json { "name": "angular2-quickstart", "version": "1.0.0", "scripts": { "tsc": "tsc", "tsc:w": "tsc -w", "lite": "lite-server", "start": "concurrent \"npm run tsc:w\" \"npm run lite\" " }, "license": "ISC", "dependencies": { "angular2": "2.0.0-beta.0", "systemjs":

Shim vs. Sham: What is the difference?

大城市里の小女人 提交于 2019-12-03 05:28:32
问题 What is the difference between a shim an a sham? Is it enough to include es5-shim.min.js and es6-shim.min.js or should I also include es5-sham.min.js and es6-sham.min.js? 回答1: According to this Github page the shims include all monkey-patches that faithfully represent the ES5 features. In other words: you can use the features provided by these files as if you were using ES5 proper. The shams, however contain those features that can not be emulated with other code. They basically provide the

WordPress - Enqueue scripts for only if LT IE 9

半世苍凉 提交于 2019-12-03 04:38:58
问题 In a WordPress theme, how do you conditionally include scripts for ie8 and below? This is primarily to apply polyfills for various html5/css3 features. I see that wp has the $is_IE variable which can be used as a conditional to only include scripts for IE. Is there a way to add the script for only certain versions of IE though rather than all of them? This is simple with some HTML ie conditional comments, but I'd like to include the scripts all in the same place in my functions file.

Modernizr with Respond.js

只谈情不闲聊 提交于 2019-12-03 01:52:10
问题 I am carefully assessing the best way to utilize Modernizr and Respond.js for responsive design and have a couple of questions for the community. Firstly, it is my understanding that when bundling Modernizr with Respond.js, no other coding or tests are required for media query support in IE8 and below. In other words, when Respond.js is bundled with Modernizr I merely have to load Modernizr in my source to get Respond.js active. Correct? Secondly, do you believe this is the most efficient way