I am developing a chrome extension and I am creating a side panel using an iframe element.
I have an object that stores styles for the corresponding iframe:
const sidePanelStyle = {
background: 'white',
// some other vars
};
I create the iframe and assign my settings:
let sidePanel = document.createElement('iframe');
Object.assign(sidePanel.style, sidePanelStyle);
Everything works, but when before I did
sidePanel.style = Object.assign(sidePanel.style, sidePanelStyle);
it did not merge anything into the sidePanel.style (I expected that .assign() returns a merged object, as per MDN).
I am new to JS, so the questions are:
- What exactly I am missing with
Object.assign()? - What is the best practice to assign multiple settings properties to an object from the existing framework and what is the best practice to keep them in my source code (a separate module? one or more objects? etc.).
While returning a merged object is redundant (the .assign() method merges everything into the first argument), I am still curios why it does not work, when the object is returned.
const sidePanelStyle = {
background: 'gray',
height: '100%',
padding: '20px',
width: '400px',
position: 'fixed',
top: '0px',
right: '0px',
zIndex: '9000000000000000000',
};
let sidePanel = document.createElement('iframe');
// this works fine
// Object.assign(sidePanel.style, sidePanelStyle);
// this doesn't
sidePanel.style = Object.assign(sidePanel.style, sidePanelStyle);
document.body.appendChild(sidePanel);