Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tatsuro-ueda/3719624 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/3719624 to your computer and use it in GitHub Desktop.
CoffeeScriptでグローバルオブジェクトを動かすには

まずCoffeeで下記のように書いて

root = exports ? this
root.foo = -> 
	alert 'Hello World'
	return

HTMLから下記のように呼ぶ

<p><input type="button" value="ダイアログ表示" onclick="foo()" /></p>
<pre>
	<script type="text/javascript" charset="utf-8">
		<!--
		(function() {
		  var root;

		  root = typeof exports !== "undefined" && exports !== null ? exports : this;

		  root.foo = function() {
		    alert('Hello World');
		  };

		}).call(this);
		-->
	</script>
	<noscript>
		JavaScriptが利用できません。
	</noscript>
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment