Created
October 11, 2011 08:28
-
-
Save gkmngrgn/1277567 to your computer and use it in GitHub Desktop.
Coffee Compilation
This file contains hidden or 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
# Copyright (c) 2011, the <your_company> project authors. Please don't see the | |
# AUTHORS file for details. All rights reserved. Use of this source code is | |
# governed by a BSD-style license that can be found in the LICENSE file. | |
# Simple test program invoked with an option to eagerly | |
# compile all code that is loaded in the isolate. | |
# VMOptions=--fuu_dart | |
class HelloCoffeeTest | |
test_main: -> | |
console.log "Hello, Coffee man!" | |
new HelloCoffeeTest().test_main() |
This file contains hidden or 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
(function() { | |
var HelloCoffeeTest; | |
HelloCoffeeTest = (function() { | |
function HelloCoffeeTest() {} | |
HelloCoffeeTest.prototype.test_main = function() { | |
return console.log("Hello, Coffee man!"); | |
}; | |
return HelloCoffeeTest; | |
})(); | |
new HelloCoffeeTest().test_main(); | |
}).call(this); |
He isn't, that code is what gets generated from the CoffeeScript above.
He could call (function(){...})(); instead but in that case "this" inside of (function(){}) will belong to global object. however, in this case it belongs to parent scope.
Guys that code is generated. If anything is worth discussing it is why the coffeescript compiler does that...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's the CoffeeScript compiler doing it, and
.call()
is actually undefined behavior in Javascript; normally the browser will do what you're stating, but if you"use strict";
, it actually does.call(undefined)
and then promptly dies.That's why.