I've been exploring method chaining in Javascript, inspired by jQuery. I created a wrapper around an array that can accept coordinate points and transformation methods. The syntax generally looks like this:
myPath = new Path().move({x:50,y:50}).line({x:20,y:20}).rotate(Math.PI/3);
It works well and is more readable than a string of coordinates. Now I want to duplicate the existing path by concatenating its reverse:
// create a symmetrical path.
myPath = new Path().move().line().etc().etc.concat(myPath.reverse());
However, this fails because myPath is unknown as an argument to concat. It works when I do:
var myPath = new Path();
myPath.move().line().etc().etc().concat(myPath.reverse());
I'm wondering if there is a shorter way in Javascript to immediately assign the new object to the variable definition? If not possible in Javascript, I'd like to know if it's achievable in other languages.
Regards, Jeroen.