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

1

5

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;
Eluviation answered 4/10, 2016 at 11:50 Comment(4)
Are you sure that's the line causing the error? I can't replicate thatBhagavadgita
Interesting. I'll update the question with the full file. I wonder if encapsulating it all in an object is the causeEluviation
a minimal, complete and verifiable example of code that demonstrates the issue would be betterBhagavadgita
It could well be that 'self' is a reserved word in IE11 Strict - try changing it to 'myself' or 'currElm' and see what happens.Uppity
E
7

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')
Eluviation answered 6/10, 2016 at 14:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.