Created
March 12, 2010 16:39
-
-
Save rhyolight/330495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Method 2: constructor returning an object literal with methods attached | |
function Rectangle2(w,h) { | |
var width = w, height = h; | |
return { | |
getWidth: function() { return width; }, | |
getHeight: function() { return height; }, | |
setWidth: function(w) { width = w; }, | |
setHeight: function(h) { height = h; }, | |
area: function() { return width * height } | |
}; | |
} | |
function PositionedRectangle2(w,h,xIn,yIn) { | |
var x = xIn, | |
y = yIn, | |
rect = new Rectangle2(w,h), | |
me = { | |
getX: function() { return x; }, | |
setX: function(xIn) { this.x = xIn; }, | |
getY: function() { return y; }, | |
setY: function(yIn) { this.y = yIn; } | |
}; | |
return mixin(rect, me); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment