5

var self = thisIE11 から、読み取り専用変数であると言われましたが、宣言ポイントの後に何も割り当てていません。唯一の変数は、変化している高さです。とはいえ、使用時に変更することはできます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();
    });

ここに画像の説明を入力

次のエラーが表示されますSCRIPT5045: Assignment to read-only properties is not allowed in strict mode

Microsoftによれば、読み取り専用プロパティを書き換えることはできないはずです。私は信じていません。では、なぜエラーが発生するのですか?

  • 読み取り専用プロパティ
  • 読み取り専用プロパティへの書き込み
  • SCRIPT5045: strict モードでは、読み取り専用プロパティへの割り当ては許可されていません
  • JavaScript
  • var testObj = Object.defineProperties({}, { prop1: { value: 10, writable: false // by default }, prop2: { get: function () { } } }); testObj.prop1 = 20; testObj.prop2 = 30;
4

1 に答える 1

7

これは、この問題を修正することを期待していた最後のことでした。また、コメントが示唆しているように、self予約されているため、それがvarであると信じていました。

ただし、それを破った行は次のとおりです。

this.faAddons.style = '';

提案された行とは何の関係もありませんIE

もちろん、属性を空白に設定するのではなく、属性を削除するように設定しました。

this.faAddons.removeAttribute('style')
于 2016-10-06T14:31:57.757 に答える