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();
});
我收到以下错误SCRIPT5045: Assignment to read-only properties is not allowed in strict mode
根据微软的说法,您不应该能够重写只读属性。我不相信我是。那么为什么我会收到错误消息?
- 只读属性
- 写入只读属性
- SCRIPT5045:在严格模式下不允许分配给只读属性
- JavaScript
var testObj = Object.defineProperties({}, { prop1: { value: 10, writable: false // by default }, prop2: { get: function () { } } }); testObj.prop1 = 20; testObj.prop2 = 30;