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

31 lines, 12 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 = {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
25echo "area1 = $area1"
26echo "area2 = $area2"
27
28## STDOUT:
29area1 = 12
30area2 = 200
31## END