, : . , Prototypical Inheretance, , :
var MyObject = function() {
this.color = "blue";
this.p = document.createElement('p');
this.p.setAttribute("color", this.color);
}
MyObject.prototype.go = function (color) {
this.color = color;
}
, color , style. :
var MyObject = function() {
this.color = "blue";
this.p = document.createElement('p');
this.p.style.color = this.color;
}
MyObject.prototype.go = function (color) {
this.color = color;
}
( p), , . , , , obj.go('red'). , , color MyObject color. , p:
var MyObject = function() {
this.color = "blue";
this.p = document.createElement('p');
this.p.style.color = this.color;
}
MyObject.prototype.go = function (color) {
this.color = color;
this.updateColor();
}
MyObject.prototype.updateColor = function () {
this.p.style.color = this.color;
}
:
var MyObject = function() {
this.color = "blue";
this.p = document.createElement('p');
}
var obj = new MyObject();
obj.p.style.color = 'red';
. , .