Nick_Tulett
15 years agoNew Contributor
Support for prototypal inheritance in JScript broken in 7.52
I'd like to write a script in JScript that uses prototypal inheritance, such as:
Object["create"] = function (o) {
function F() {}
F["prototype"] = o;
return new F();
};
function BaseObject(name) {
this["name"] = name;
}
BaseObject["prototype"] = {
writeName: function () {
Log["Message"](this["name"]);
},
changeName: function (newName) {
this["name"] = newName;
}
}
function NobleObject(name) {
BaseObject["call"](this, name);
this["rank"] = "noble";
}
NobleObject["prototype"] = Object["create"](BaseObject["prototype"]);
NobleObject["prototype"]["changeRank"] = function (newRank) {
this["rank"] = newRank;
}
NobleObject["prototype"]["writeRank"] = function () {
Log["Message"](this["rank"]);
}
function testObjects() {
myBase = new BaseObject("testBO");
myBase["writeName"]();
myBase["changeName"]("newTestBO");
myBase["writeName"]();
myNoble = new NobleObject("testNO");
myNoble["writeName"]();
myNoble["writeRank"]();
myNoble["changeName"]("newTestNO");
myNoble["writeName"]();
myNoble["changeRank"]("tarnished");
myNoble["writeRank"]();
}
This is valid JScript and runs on TC 5 but TC 7.52 flags the changeRank method as being a duplicate method name (presumably it's confused by the "prototype" call). Could we please remove this check from JScript scripts as it is broken?
In a similar vein, the Code Explorer only shows the "constructor" functions and not any of the prototype functions. Can this be fixed, too?
Object["create"] = function (o) {
function F() {}
F["prototype"] = o;
return new F();
};
function BaseObject(name) {
this["name"] = name;
}
BaseObject["prototype"] = {
writeName: function () {
Log["Message"](this["name"]);
},
changeName: function (newName) {
this["name"] = newName;
}
}
function NobleObject(name) {
BaseObject["call"](this, name);
this["rank"] = "noble";
}
NobleObject["prototype"] = Object["create"](BaseObject["prototype"]);
NobleObject["prototype"]["changeRank"] = function (newRank) {
this["rank"] = newRank;
}
NobleObject["prototype"]["writeRank"] = function () {
Log["Message"](this["rank"]);
}
function testObjects() {
myBase = new BaseObject("testBO");
myBase["writeName"]();
myBase["changeName"]("newTestBO");
myBase["writeName"]();
myNoble = new NobleObject("testNO");
myNoble["writeName"]();
myNoble["writeRank"]();
myNoble["changeName"]("newTestNO");
myNoble["writeName"]();
myNoble["changeRank"]("tarnished");
myNoble["writeRank"]();
}
This is valid JScript and runs on TC 5 but TC 7.52 flags the changeRank method as being a duplicate method name (presumably it's confused by the "prototype" call). Could we please remove this check from JScript scripts as it is broken?
In a similar vein, the Code Explorer only shows the "constructor" functions and not any of the prototype functions. Can this be fixed, too?