Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assignment to read-only properties is not allowed in strict mode IE11

I have been told by IE11 that var self = this is a read-only variable... Yet I am not assigning anything to it after its declaration point. The only variable is height that is changing. Even though, i would be able to change it when using var

'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

I get the following error SCRIPT5045: Assignment to read-only properties is not allowed in strict mode

According to Microsoft you should not be able to re-write a read-only property. I don't believe I am. So why do I get the error?

  • Read-only property
  • Writing to a read-only property
  • SCRIPT5045: Assignment to read-only properties is not allowed in strict mode
  • JavaScript
  • var testObj = Object.defineProperties({}, { prop1: { value: 10, writable: false // by default }, prop2: { get: function () { } } }); testObj.prop1 = 20; testObj.prop2 = 30;
like image 737
Jamie Hutber Avatar asked Oct 04 '16 11:10

Jamie Hutber


1 Answers

This was the last thing that I ever expected to fix this issue. I did also as comments have suggested believe it was the self var as it is reserved.

However the line that broke it was:

this.faAddons.style = '';

Nothing to do with the line that IE suggested.

So of course, I set this to remove the attribute rather than just setting it to blank.

this.faAddons.removeAttribute('style')
like image 112
Jamie Hutber Avatar answered Nov 20 '22 02:11

Jamie Hutber