instanceof-basic.js 488 B

12345678910111213141516171819202122232425262728
  1. load("test-common.js");
  2. try {
  3. function Foo() {
  4. this.x = 123;
  5. }
  6. var foo = new Foo();
  7. assert(foo instanceof Foo);
  8. function Base() {
  9. this.is_base = true;
  10. }
  11. function Derived() {
  12. this.is_derived = true;
  13. }
  14. Object.setPrototypeOf(Derived.prototype, Base.prototype);
  15. var d = new Derived();
  16. assert(d instanceof Derived);
  17. assert(d instanceof Base);
  18. console.log("PASS");
  19. } catch(e) {
  20. console.log("FAIL: " + e);
  21. }