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') 
相关问题