Number.prototype.triple = function (â??â??) { var nm = this.valueOf(â??â??) * 3; return nm; } var num = new Number(3.0); alert(num.triple(â??â??));
Declare the data member with var instead of this. The purpose behind data hiding is to control how the data is accessed or updated.
Use the tHRow statement to trigger an error. Then implement try...catch in the calling application:
if (typeof value != "number") { throw "NotANumber"; }
Unlike the event object, there are more than just model differences involved. Not only is the property different, but so is the value thatâ??s assigned to the property.
Hereâ??s one approach to creating the objects:
function Control(â??â??) { var state = 'on'; var background = '#fff'; this.changeState = function(â??â??) { if (state == 'on') { state = 'off'; background = '#000'; } else state = 'on'; background = '#fff'; }; this.getState = function(â??â??) { return state; }; this.getColor = function(â??â??) { return background; }; }