javascriptconstructoramber-smalltalk

How do I translate JavaScript constructors to Amber Smalltalk?


I use the paperjs graphical objects library with Amber Smalltalk.

I want to translate the following Javascript constructors for a Point object to Amber Smalltalk

paper.Point(x, y)
paper.Point(array)
paper.Point(object)
paper.Point(size)
paper.Point(point) 

The following Smalltalk

paper Point new inspect

gives a point

{ x: 0, y: 0 } 

To construct an array in an Amber workspace I do

#(100 100)

The printIt is

 an Array (100 100) 

However

 paper Point value: #(100 100)    

gives nil as the result.

Question

How do I translate the paper.Point(array) constructor from JavaScript to Amber as well as the other constructurs?

References

  1. http://paperjs.org/reference/point/
  2. https://github.com/amber-smalltalk/amber/wiki/Wrapping-javascript-constructors-recipe
  3. Demo of translated code so far (contains fabricjs and svg.js examples as well)

Solution

  • The Amber Smalltalk equivalent of new paper.Paper(100,100) (JavaScript) is

    paper Point newValue: 100 value: 100
    

    This gives

     { x: 100, y: 100 } 
    

    Reference

    https://github.com/amber-smalltalk/amber/wiki/Call-javascript-constructors-with-arguments