Skip to content

Instantly share code, notes, and snippets.

@msuarz
Created February 14, 2012 01:55
Show Gist options
  • Save msuarz/1822440 to your computer and use it in GitHub Desktop.
Save msuarz/1822440 to your computer and use it in GitHub Desktop.
Calculator
class exports.Calculator
square: (x) -> x * x
exports.Calculator = (function() {
function Calculator() {}
Calculator.prototype.square = function(x) {
return x * x;
};
return Calculator;
})();
exports.Calculator = function() {
this.square = function(x) {
return x * x;
};
};
@jperkelens
Copy link

var Calculator = function() {
...
... this.square = function(x) {
... return x * x;
... };
... };
undefined

var c = Calculator();
undefined
c.square(5);
TypeError: Cannot call method 'square' of undefined
at repl:1:3
at REPLServer.eval (repl.js:80:21)
at repl.js:190:20
at REPLServer.eval (repl.js:87:5)
at Interface. (repl.js:182:12)
at Interface.emit (events.js:67:17)
at Interface._onLine (readline.js:162:10)
at Interface._line (readline.js:426:8)
at Interface._ttyWrite (readline.js:603:14)
at ReadStream. (readline.js:82:12)
at ReadStream.emit (events.js:88:20)
at ReadStream._emitKey (tty.js:331:10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment