严格模式IE11中不允许分配只读属性

Jam*_*ber 5 javascript internet-explorer use-strict internet-explorer-11

IE11告诉我,这var self = this是一个只读变量...但是,在声明点之后,我没有为其分配任何内容。唯一的变量是高度在变化。即使,我将能够在使用时更改它var

“严格使用”;

    var onDocumentLoad = require('fe-client-utils/src/dom/onDocumentLoad');
    var onOrientationChange = require('fe-client-utils/src/dom/onOrientationChange');

    var faPageHeight = function () {

    };

    var FA = {
        init: function () {
            this.faAddons = document.querySelector('.fa-addons');
            this.faFooter = document.querySelector('.fa-footer');
            this.extraWideChild = document.querySelector('.extraWide > div');
            this.extraWide = document.querySelector('.extraWide');
            this.faPages = document.querySelector('.fa-pages');
            this.pageContent = document.getElementById('page-content');
            this.faPageItems =  document.querySelectorAll('.fa-page');
            this.moveElements();
            this.faPageHeight();
        },
        faPageHeight: function () {
            var height = 0;
            var self = this;

            Object.keys(self.faPageItems).forEach(function (item, index) {
                height += self.faPageItems[item].offsetHeight;
            });

            height += 150;
            this.extraWideChild.style.height = height+'px';
        },
        moveElements: function () {
            this.faAddons.style = '';

            this.pageContent.appendChild(this.faAddons);
            this.pageContent.appendChild(this.faFooter);

            this.faFooter.style.display = 'block';
        }
    }

    onDocumentLoad(function () {
        FA.init();
    });

    onOrientationChange(function () {
        FA.faPageHeight();
    });
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我收到以下错误 SCRIPT5045: Assignment to read-only properties is not allowed in strict mode

根据Microsoft,您应该不能重新编写一个只读属性。我不相信我。那么,为什么会出现错误?

  • 只读属性
  • 写入只读属性
  • SCRIPT5045:在严格模式下不允许分配只读属性
  • 的JavaScript
  • var testObj = Object.defineProperties({}, { prop1: { value: 10, writable: false // by default }, prop2: { get: function () { } } }); testObj.prop1 = 20; testObj.prop2 = 30;

Jam*_*ber 6

这是我曾期望解决此问题的最后一件事。我也做过评论,认为self这是保留的var。

但是,破坏它的行是:

this.faAddons.style = '';
Run Code Online (Sandbox Code Playgroud)

IE建议的行无关。

因此,当然,我将其设置为删除属性,而不仅仅是将其设置为空白。

this.faAddons.removeAttribute('style')
Run Code Online (Sandbox Code Playgroud)