Try instead:
var foo = new Shape(40,40,50,50);
s.addShape(foo);
alert(foo.x);
...alternatively, the code you posted should work if you rewrite addShape as such:
CanvasState.prototype.addShape = function(shape) {
// current addShape code here
return shape;
}
...but that's most likely not the best implementation strategy.