| 1 | ## our_shell: ysh
|
| 2 |
|
| 3 | #### Object() creates prototype chain
|
| 4 |
|
| 5 | func Rect_area(this) {
|
| 6 | return (this.x * this.y)
|
| 7 | }
|
| 8 |
|
| 9 | var Rect = Object(null, {area: Rect_area})
|
| 10 |
|
| 11 | var rect1 = Object(Rect, {x: 3, y: 4})
|
| 12 | var 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 |
|
| 22 | var area1 = rect1.area()
|
| 23 | var area2 = rect2.area()
|
| 24 |
|
| 25 | pp test_ ([rect1.x, rect1.y])
|
| 26 | echo "area1 = $area1"
|
| 27 |
|
| 28 | pp test_ ([rect2.x, rect2.y])
|
| 29 | echo "area2 = $area2"
|
| 30 |
|
| 31 | #pp test_ (rect1.nonexistent)
|
| 32 |
|
| 33 | ## STDOUT:
|
| 34 | (List) [3,4]
|
| 35 | area1 = 12
|
| 36 | (List) [10,20]
|
| 37 | area2 = 200
|
| 38 | ## END
|