File indexing completed on 2024-04-28 15:28:38
0001 /////////////////////////////////////////////////////// 0002 0003 function Square(x) 0004 { 0005 this.x = x; 0006 } 0007 0008 new Square(0); // create prototype 0009 0010 function Square_area() { return this.x * this.x; } 0011 Square.prototype.area = Square_area; 0012 var s = new Square(3); 0013 shouldBe("s.area()", "9"); 0014 0015 /////////////////////////////////////////////////////// 0016 0017 function Item(name){ 0018 this.name = name; 0019 } 0020 0021 function Book(name, author){ 0022 this.base = Item; // set Item constructor as method of Book object 0023 this.base(name); // set the value of name property 0024 this.author = author; 0025 } 0026 Book.prototype = new Item; 0027 var b = new Book("a book", "Fred"); // create object instance 0028 //edebug(e"b.name")); 0029 shouldBe("b.name", "'a book'"); 0030 shouldBe("b.author", "'Fred'"); // outpus "Fred" 0031 0032 /////////////////////////////////////////////////////// 0033 0034 shouldBe("delete Boolean.prototype", "false"); 0035