instanceof-basic.js 463 B

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