|
- Object.prototype.extend = function (Parent) {
- this.prototype = new Parent();
- }
- Rectangle = function (width, height) {
- this.width = width;
- this.height = height;
- }
- Rectangle.prototype.area = function () {
- return this.width * this.height;
- }
- Square = function (width) {
- this.__proto__.width = width;
- this.__proto__.height = width;
- this.whoami = function () {
- return "I am a Square.";
- }
- }
- Square.extend(Rectangle);
-
- var s = new Square(5);
- document.writeln(s.area()); // The output is 25.
- document.writeln(s.whoami()); // The output is "I am a Square."
- Object.prototype.extend = function (Parent) {
- this.prototype = new Parent();
- }
- Rectangle = function (width, height) {
- this.width = width;
- this.height = height;
- }
- Rectangle.prototype.area = function () {
- return this.width * this.height;
- }
- Square = function (width) {
- this.__proto__.width = width;
- this.__proto__.height = width;
- this.whoami = function () {
- return "I am a Square.";
- }
- }
- Square.extend(Rectangle);
- var s = new Square(5);
- document.writeln(s.area()); // The output is 25.
- document.writeln(s.whoami()); // The output is "I am a Square."
复制代码
以上代码存在很多问题,不知你能说出几个? |
|