method: (y) -> @x + y a = new A 3 b = new A 4 a.method 6 b.method 7 var A, a, b; A = (function(){ A.displayName = 'A'; var prototype = A.prototype; var constructor = A; function A(num){ this.x = num; } prototype.method = function(y){ return this.x + y; }; return A; }()); a = new A(3); b = new A(4); a.method(6); b.method(7); From http://livescript.net/ Saturday, 20 April, 13
-> ret -> ret @last = [tag, value, @line] parameters: !(arrow, offset) -> if @last.0 is \) is @last.1 @lpar.0 = \PARAM( @last.0 = \)PARAM return if arrow is \-> then @token \PARAM( '' else for t, i in @tokens by -1 when t.0 in <[ NEWLINE INDENT THEN => ( ]> then break @tokens.splice (i+1), 0 [\PARAM( '' t.2] if offset then @tokens.splice (@tokens.length + offset), 0 [\)PARAM '' t.2] else @token \)PARAM '' Saturday, 20 April, 13
= Scope.root = new Scope, ...options} if saveTo = delete o.saveScope o.scope = saveTo.savedScope or= o.scope delete o.filename o.indent = if bare = delete o.bare then '' else TAB if /^\s*(?:[/#]|javascript:)/test @lines.0?code prefix = @lines.shift!code + \\n if delete o.eval and @chomp!lines.length if bare then @lines.push Parens @lines.pop! else @makeReturn! code = @compileWithDeclarations o # Wrap everything in a safety closure unless requested not to. bare or code = "(function(){\n#code\n}).call(this);\n" [prefix] + code Saturday, 20 April, 13
if i = @neck! rest = @lines.splice i, 9e9 pre = @compile o @lines = rest return pre unless post = @compile o (pre and "#pre\n") + if @scope then that.emit post, o.indent else post Saturday, 20 April, 13