Object.defineProperty alternative for IE8

前端 未结 2 915
有刺的猬
有刺的猬 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:50

    IE8 does not support getter/setter functions on properties of non DOM objects.

    The "solution" here is to not rely on property getters, and use a full getter function instead.

    AutosizeInput.prototype.getOptions = function() {
      return this._options;
    };
    
    var input = new AutoresizeInput();
    input.getOptions();
    

    Or, instead of keeping this._options as an "internal" variable, just drop the underscore allow access directly. This way you need no magic at all.

    var AutoresizeInput = function() {
      this.options = {};
    }
    
    var input = new AutoresizeInput();
    input.options();
    

提交回复
热议问题