File: Prototype.js

package info (click to toggle)
kjs 5.103.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,020 kB
  • sloc: cpp: 36,704; javascript: 5,079; yacc: 790; perl: 191; sh: 52; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 890 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
///////////////////////////////////////////////////////

function Square(x)
{
  this.x = x;
}

new Square(0); // create prototype

function Square_area() { return this.x * this.x; }
Square.prototype.area = Square_area;
var s = new Square(3);
shouldBe("s.area()", "9");

///////////////////////////////////////////////////////

function Item(name){ 
  this.name = name;
}

function Book(name, author){
  this.base = Item;         // set Item constructor as method of Book object
  this.base(name);           // set the value of name property
  this.author = author;
}
Book.prototype = new Item;
var b = new Book("a book", "Fred");        // create object instance
//edebug(e"b.name"));
shouldBe("b.name", "'a book'");
shouldBe("b.author", "'Fred'");                  // outpus "Fred" 

///////////////////////////////////////////////////////

shouldBe("delete Boolean.prototype", "false");