Skip to content

Instantly share code, notes, and snippets.

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

下記コードではtimerという関数をグローバルオブジェクト化している。

root = exports ? this
root.timer = window.setInterval(
	->
		dat = new Date()
		document.getElementById('result').innerHTML = dat.toLocaleTimeString()
	1000
)

window.onload = timer

下記コードではprocessという関数をグローバルオブジェクト化している。

root = exports ? this
root.process = ->
	name = document.fm.name.value
	alert('こんにちは、' + name + 'さん!')
	false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment