Last active
November 12, 2018 01:55
-
-
Save jizusun/5ebc991124f46954a023ea1130d147ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 54: Object - is | |
// To do: make all tests pass, leave the assert lines unchanged! | |
// Follow the hints of the failure messages! | |
// Shape - superclass | |
function Shape() { | |
this.x = 0; | |
this.y = 0; | |
} | |
// superclass method | |
Shape.prototype.getX = function(x, y) { | |
return this.x; | |
}; | |
// Rectangle - subclass | |
function Rectangle() { | |
Shape.call(this); // call super constructor. | |
} | |
// subclass extends superclass | |
assert.equal(new Shape().getX(), 0) | |
Rectangle.prototype.constructor = Rectangle; | |
var rect = new Rectangle(); | |
// ===================== | |
describe("Shape object", function() { | |
it('x, y are instance properties of Shape', function() { | |
assert.equal(Shape.x, undefined); | |
assert.equal(new Shape().x, 0); | |
}); | |
}); | |
describe("`move` is one of the instance methods, defined on `Shape.prototype`", function() { | |
it('cannot be invoked on the class ', function() { | |
assert.throws(function() { | |
Shape.getX(); | |
}); | |
}); | |
it('can be invoked on an instance', function() { | |
assert.equal(new Shape().getX(), 0); | |
}); | |
it('can also be invoked on the protoype of the class, but would not get the correct result', function() { | |
assert.equal(Shape.prototype.getX(), void 0); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment