JavaScript subclassing
Am I doing something wrong or is this somehow broken?
function ExtendedString() {};
ExtendedString.prototype = new String;
var str = new ExtendedString('some text.')
alert(str.length);
// -> 0 in Safari and IE
// -> an error in Firefox
// (String.prototype.toString called on incompatible Object)
4 comments
Comments
-
IE doesn’t allow you to “sub-class” native objects. The same thing happens if you try to overwrite Array, too. (In this case, a similar problem must be happening in the other browsers.)
Thu, February 08 at 13:21 PM
-
http://dean.edwards.name/weblog/2006/11/hooray/
Thu, February 08 at 13:45 PM