-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
45 lines (29 loc) · 725 Bytes
/
test.js
File metadata and controls
45 lines (29 loc) · 725 Bytes
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
36
37
38
39
40
41
42
43
44
///Ubersimple prototypal {Io-lang|Lua}-style inheritance in js
///================
///```javascript
var Subj=require("./subject").Subj
//`define something
var S0=Subj.def({
name:"Something",
whoami:function(){
return this.name}})
//`instantiate it
var s0=S0.new({
name:"Something1"})
expect(s0.whoami(),"Something1")
//`inherit
var S1=S0.def({
name:"Other",
whoami:function(){
return S0.whoami.apply(this,arguments)+" One"}})
//`instantiate inherited
var s1=S1.new({
name:"Another"})
expect(s1.whoami(),"Another One")
var S2=S1.def({
init:function(options){
options.addname &&
(this.name+=" "+addname)}})
var s2=S2.new({addname:"No"})
expect(s2.whoami(),"Other No One")
///```