OILS / spec / ysh-object.test.sh View on Github | oilshell.org

38 lines, 16 significant
1## our_shell: ysh
2
3#### Object() creates prototype chain
4
5func Rect_area(this) {
6 return (this.x * this.y)
7}
8
9var Rect = Object(null, {area: Rect_area})
10
11var rect1 = Object(Rect, {x: 3, y: 4})
12var rect2 = Object(Rect, {x: 10, y: 20})
13
14# This could change to show the object?
15# pp test_ (rect)
16
17# TODO: This should be a bound function
18#pp asdl_ (rect)
19#pp (rect.area)
20#pp (rect->area)
21
22var area1 = rect1.area()
23var area2 = rect2.area()
24
25pp test_ ([rect1.x, rect1.y])
26echo "area1 = $area1"
27
28pp test_ ([rect2.x, rect2.y])
29echo "area2 = $area2"
30
31#pp test_ (rect1.nonexistent)
32
33## STDOUT:
34(List) [3,4]
35area1 = 12
36(List) [10,20]
37area2 = 200
38## END