3
IE11告訴我,var self = this
是一個只讀變量......但是我沒有在其聲明點之後分配任何東西。唯一的變量是正在改變的高度。儘管如此,我可以在使用時更改它var
在嚴格模式下不允許分配只讀屬性IE11
'use strict';
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:分配給只讀屬性是不允許的嚴格模式
- 的JavaScript
var testObj = Object.defineProperties({}, { prop1: { value: 10, writable: false // by default }, prop2: { get: function() { } } }); testObj.prop1 = 20; testObj.prop2 = 30;
您確定這是導致錯誤的行嗎?我無法複製那 –
有趣的。我將用完整文件更新問題。我想知道是否將它全部封裝在一個對象中是原因 –
代碼的一個最小,完整且可驗證的示例,它可以證明問題會更好 –