While experimenting with adding CSS rules using JavaScript, I encountered this interesting line of code. I am having trouble understanding how the return statement works and how I can adapt it for my own project.
var sheet = function() {
var style = document.createElement('style');
document.head.appendChild(style);
return style.sheet;
}();
I was thinking about encapsulating it within a module like this:
var AddCssStyles = {
makeSheet: function(){
this.stylesheet = document.CreateElement...
// return a stylesheet for later use
}
}
var navigationHeight = Object.create(AddCssStyles);
navigationHeight.makeSheet();
This approach would allow me to access the stylesheet using navigationHeight.stylesheet in order to make necessary changes.