标签: polyfills

为什么console.log()polyfill不使用Function.apply()?

我一直在寻找一些流行的console.log()包装纸/填料:

我注意到他们都接受多个arguments,但他们都做这样的事情:

console.log(arguments);
Run Code Online (Sandbox Code Playgroud)

这导致像这样的输出(在Chrome中):

<code>console.log()</code>也接受多个参数,这样就可以产生(恕我直言)卓越的输出:</p>

<pre><code>console.log.apply(console, arguments)
</code></pre><a target=Run Code Online (Sandbox Code Playgroud)

这导致像这样的输出(在Chrome中):

<code>console.log.apply()</code>多个参数?或者这仅仅是品味或节省字节的问题?</p> </div>
        <p>
          <a href=javascript debugging polyfills

7
推荐指数
1
解决办法
1754
查看次数

使用MDN结合填充物是否存在风险?

我开发了一个需要该bind方法的Javascript库.不幸的是,bindIE8不支持.

MDN网站上有一个polyfill ,效果很好.

我的问题是:这个polyfill和其他Javascript库之间是否存在问题或可能存在不兼容性?

在任何情况下都可以安全使用?

javascript polyfills

7
推荐指数
1
解决办法
1778
查看次数

IE输入事件是否满足?

我想知道是否有一个polyfill支持IE11中contenteditable输入事件?

我特别谈到这个事件:http://jsfiddle.net/ch6yn/

无论来源如何,只要在可信任的 div 上发生变化,就会触发(例如复制/粘贴/拖放/类型等).

<div contenteditable="true" id="editor">Please type something in here</div>
<script>
document.getElementById("editor").addEventListener("input", function() {
    alert("input event fired");
}, false);
</script>
Run Code Online (Sandbox Code Playgroud)

events internet-explorer input contenteditable polyfills

7
推荐指数
2
解决办法
4123
查看次数

现在,如果不推荐使用yepnope,如何使用modernizr加载条件js文件?

现在使用modernizr加载条件javascript文件有哪些好的做法,因为在最新版本的modernizr中不推荐使用yepnope和.load.

以前能够使用.load函数. http://modernizr.com/docs/#load

Modernizr.load({
  test: Modernizr.geolocation,
  yep : 'geo.js',
  nope: 'geo-polyfill.js'
});
Run Code Online (Sandbox Code Playgroud)

现在.load与yepnope一起被弃用. https://github.com/SlexAxton/yepnope.js/

在yepnope被弃用之前参考答案 使用Modernizr加载脚本...不工作

modernizr polyfills yepnope ruby-on-rails-4

7
推荐指数
1
解决办法
390
查看次数

如何在打字稿(模块)中向Globals添加polyfill

我能够为Array#includes找到一个polyfill(堆栈溢出)并将其添加到typescript但是在我的文件中添加一个小的导入后它变成了一个模块(我明白他们为什么要这样做导出,但为什么要导入)我再也无法修改全局命名空间了.

如何修复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/includes#Polyfill
if (!Array.prototype.includes) {
    Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
        'use strict';
        var O = Object(this);
        var len = parseInt(O.length, 10) || 0;
        if (len === 0) {
            return false;
        }
        var n = parseInt(arguments[1], 10) || 0;
        var k;
        if (n >= 0) {
            k = n;
        } else {
            k = len + n;
            if (k < 0) {k …
Run Code Online (Sandbox Code Playgroud)

shim polyfills typescript

7
推荐指数
2
解决办法
8867
查看次数

在Angular 2中添加polyfill代码

如何在Angular 2 cli项目中添加polyfill的代码?

例如,我想使用Mozilla MDN中的以下polyfill :

if (!Array.prototype.includes) {
  Object.defineProperty(Array.prototype, 'includes', {
    value: function(searchElement, fromIndex) {
      if (this == null) { throw new TypeError('"this" is null or not defined'); }
      var o = Object(this);
      var len = o.length >>> 0;
      if (len === 0) { return false; }
      var n = fromIndex | 0;
      var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
      while (k < len) {
        if (o[k] === searchElement) { return …
Run Code Online (Sandbox Code Playgroud)

polyfills angular

7
推荐指数
1
解决办法
1万
查看次数

获取重试请求(失败时)

我正在使用浏览器的本机提取API来处理网络请求.此外,我正在使用whatwg-fetch polyfill用于不支持的浏览器.

但是,如果请求失败,我需要重试.现在我找到了这个npm包whatwg-fetch-retry,但他们没有解释如何在他们的文档中使用它.有人可以帮我这个或建议我另类吗?

javascript polyfills fetch-api

7
推荐指数
4
解决办法
6751
查看次数

如何在Angular App中添加URL Polyfill

我们想在我们的应用程序中使用https://github.com/auth0/angular2-jwt.现在它说,Internet Explorer 11支持需要URL填充.需要帮助或步骤才能在Angular App中添加此polyfill.

polyfills angular

7
推荐指数
2
解决办法
3390
查看次数

导入文本编码的polyfill后,为什么在IE11中出现“ ReferenceError:'TextEncoder'未定义”的问题?

我正在尝试对库fetch-readystream(https://github.com/jonnyreeves/fetch-readystream)进行轮询。我已经添加了polyfills,并且大多数事情都能正常工作,但是我仍然收到有关TextEncoder的错误ERROR ReferenceError: 'TextEncoder' is undefined

我添加了必需的pollyfills:web-streams-polyfill,text-encoding和babel-polyfill。我尝试了这些polyfill的其他等效方法,但遇到了同样的问题。

polyfills.ts所需要的IE进口,我注释掉后的文件。

import 'web-streams-polyfill'; // Run `npm install --save web-streams-polyfill`.
import 'text-encoding'; // Run `npm install --save text-encoding`.
import 'babel-polyfill'; // Run `npm install --save babel-polyfill`.
Run Code Online (Sandbox Code Playgroud)

我也尝试将脚本添加到 index.html

<script src="node_modules/text-encoding/lib/encoding-indexes.js"></script>
<script src="node_modules/text-encoding/lib/encoding.js"></script>
Run Code Online (Sandbox Code Playgroud)

我不希望有任何错误,但是我得到了:

ERROR ReferenceError: 'TextEncoder' is undefined
   "ERROR"
   {
      [functions]: ,
      __proto__: { },
      description: "'TextEncoder' is undefined",
      message: "'TextEncoder' is undefined",
      name: "ReferenceError",
      number: -2146823279,
      stack: "ReferenceError: 'TextEncoder' is undefined
   at responseParserFactory (http://localhost:4200/vendor.js:139703:3)
   at xhrTransport (http://localhost:4200/vendor.js:139960:1)
   at fetchStream …
Run Code Online (Sandbox Code Playgroud)

polyfills angular

7
推荐指数
1
解决办法
579
查看次数

如何在Microsoft Edge中使用Polyfill?

我正在探索什么是polyfill,然后观看了一个YouTube视频(https://www.youtube.com/watch?v=eSdAC8d5_Nw&t=379s),了解了如何使用polyfill在不受支持的浏览器中显示Web组件,特别是我将目标锁定在Microsoft Edge上。

我已经在YouTube视频显示时尝试了HTMLElements,并且一切正常,但是当我尝试对LitElement进行同样操作时,即使在Chrome等浏览器中也不会显示该组件。

我已经使用此链接当前正在使用的文件创建了一个Plunker文件(http://plnkr.co/edit/w4np7dbm3N9yk1DFWA3W)Index.html是我试图显示我拥有的所有组件的网页创建。我拥有的要素是<web-component></web-component><todo-view></todo-view>

Web组件是在app.js中定义的HTMLElement,其中todo-view是在todo-view.js中定义的LitElement。

在Microsoft Edge中,没有收到任何错误消息,但未显示todo-view组件。任何帮助将非常感激!

javascript web-component polyfills lit-element

7
推荐指数
1
解决办法
570
查看次数