Skip to content

@erisdev /accessors.coffee
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
class Vector
constructor: (@x, @y) ->
getX: () -> @[0]
getY: () -> @[1]
setX: (x) -> @[0] = x
setY: (y) -> @[1] = y
v = new Vector(3, 4)
ok v.x is v.getX()
ok v.y is v.getY()
var Vector, v;
Vector = function() {
function Vector(x, y) {
this.x = x;
this.y = y;
}
Vector.prototype.getX = function() {
return this[0];
};
Vector.prototype.__defineGetter__('x', Vector.prototype.getX);
Vector.prototype.getY = function() {
return this[1];
};
Vector.prototype.__defineGetter__('y', Vector.prototype.getY);
Vector.prototype.setX = function(x) {
return this[0] = x;
};
Vector.prototype.__defineSetter__('x', Vector.prototype.setX);
Vector.prototype.setY = function(y) {
return this[1] = y;
};
Vector.prototype.__defineSetter__('y', Vector.prototype.setY);
return Vector;
}();
v = new Vector(3, 4);
ok(v.x === v.getX());
ok(v.y === v.getY());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.