1 decade ago by gxxaxx
The below change is a recommended error checking / recovery for idiots (like moi) that might call the function with a non-existent string.
Not sure what the philosophy is on mucking the code up with throws and error checks.
Not sure what the philosophy is on mucking the code up with throws and error checks.
widthForString: function( s ) { if (typeof(s) == 'undefined' || s == null) { return 0; } var width = 0; for( var i = 0; i < s.length; i++ ) { width += this.widthMap[s.charCodeAt(i) - this.firstChar] + 1; } return width; },