Object.defineProperty alternative for IE8

前端 未结 2 916
有刺的猬
有刺的猬 2020-12-10 06:06

Given javascript code like the following (extracted from a plugin referenced below):

var AutosizeInput = (function () {
    function AutosizeInput(input, opt         


        
2条回答
  •  不知归路
    2020-12-10 06:39

    You can create your own something like

     if (!Object.defineProperty) {
                Object.defineProperty = function (obj, prop, descriptor) {
                    if (arguments.length < 3) { // all arguments required
                        throw new TypeError("Arguments not optional");
                    }
    
                    prop += ""; // convert prop to string
                    ...     
    

    You can find the rest of the code here:

    • https://gist.github.com/brettz9/4093766#file_html5_dataset.js
    • https://github.com/es-shims/es5-shim/blob/master/es5-sham.js

提交回复
热议问题