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(); 
    }); 

enter image description here

我收到以下錯誤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;
+0

您確定這是導致錯誤的行嗎?我無法複製那 –

+0

有趣的。我將用完整文件更新問題。我想知道是否將它全部封裝在一個對象中是原因 –

+0

代碼的一個最小,完整且可驗證的示例,它可以證明問題會更好 –

回答

2

這是最後一件事t我曾希望解決這個問題。我也如評論所暗示的那樣相信它是self var,因爲它是保留的。

然而,打破這是行:

this.faAddons.style = ''; 

無關與IE建議行。

所以當然,我設置這個刪除屬性,而不是將其設置爲空白。

this.faAddons.removeAttribute('style') 
相關問題