GithubHelp home page GithubHelp logo

fan19900404 / es5-polyfill-ie78-jq Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 459 KB

基于jq的,在ie7/8浏览器环境下,实现的es5方法垫片语法糖

License: MIT License

JavaScript 95.02% HTML 4.98%
es5 ie8 ie7

es5-polyfill-ie78-jq's Introduction

es5-polyfill-ie78-jq

基于jq的,在ie7/8浏览器环境下,实现的es5方法垫片语法糖

项目缘由

由于公司的项目,还是要求兼容IE7/8,并且在项目中已经引入了jquery1.x版本,但是并没有引入es5-shim一类的es5兼容库(理由是es5-shim 库太大?)

所以,在完成公司任务的时候,不能愉快的使用es5的Array的相关方法,非常不爽,即使jq也提供了$.each,$.map一类的方法,我还是想要使用原生方法。

在考虑到体积一类的问题,最终决定,依赖jq这个库,自己动手写个语法糖,比如

  if (!Array.prototype.map) {
    Array.prototype.map = function(callback, thisArg) {
      var that = this;
      return $.map(this, function(value, index) {
        return callback.call(thisArg, value, index, that);
      });
    };
  }

支持的API

  • Array
    • Array.isArray
    • Array.prototype.forEach
    • Array.prototype.every
    • Array.prototype.filter
    • Array.prototype.indexOf
    • Array.prototype.map
    • Array.prototype.some
  • String
    • String.prototype.trim
  • Date
    • Date.now
  • Object
    • Object.keys

引入的方法

<head>
  <script src="../lib/jquery.min.js"></script>
  <!--[if lte IE 8]>
  <script src="../dist/es5-polyfill-ie78-jq.min.js"></script>
  <![endif]-->
</head>
<body>
</body>

请先引入jquery

注意

  • 本兼容方案,是以在IE7/8环境中正常可用为标准,不关心是否和ES5完全一致,比如错误提示一致。
  • 本兼容方案出于体积考虑,只放入常用方法。
  • 本兼容方案依赖jq,请先引入jq,在引入本js。
  • 如无特殊要求,建议引入es5-shim的兼容方案。
  • 再次重申,本兼容方案,只适合于使用了jq,并且要兼容IE7/8时,可使用ES5的部分方法。

其它

github由于众所周知原因,特别慢,推荐使用 github.com.cnpmjs.org 代替github,比如本项目,原本 https://github.com/fan19900404/es5-polyfill-ie78-jq 改为 https://github.com.cnpmjs.org/fan19900404/es5-polyfill-ie78-jq

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.