How can i add an id to the constructor?
function ready() { function Rectangle(i, w, h, c) { this.id = i; this.width = w; this.height = h; this.color = c; } Rectangle.prototype.elemId = function() { return this.id = document.getElementById(); } Rectangle.prototype.doublewidth = function() { return this.width * 2; } Rectangle.prototype.doubleheight = function() { return this.height * 2; } var oneRect = new Rectangle("elem", 300, 150, "green"); oneRect.elemId().style.background = oneRect.color; oneRect.elemId().style.width = oneRect.doublewidth() + "px"; oneRect.elemId().style.height = oneRect.doubleheight() + "px"; }; document.addEventListener("DOMContentLoaded", ready); <div id="elem"></div>
idto the constructor - GrundyДа, именно так- vp_arthstyle- your object will become obsolete with each such operation. Define these operations inside the class. - vp_arth