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
run = (func, arg...) -> func arg... | |
### | |
生成的js代码: | |
var run, | |
__slice = [].slice; | |
run = function() { |
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
clearArray1 = (arr) -> | |
arr.splice 0, arr.length # 返回被删除的部分,即原数组 | |
clearArray2 = (arr) -> | |
arr.splice 0, arr.length | |
arr # 返回被清空的数组 | |
clearArray3 = (arr) -> | |
arr.splice 0, arr.length | |
return # 单独使用return,什么都不返回 |
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
var net = require('net'); | |
var tcpServer = net.createServer(); | |
tcpServer.on('connection', function(client) { | |
client.write('Hi!\n'); | |
client.write('Bye!\n'); | |
client.end(); | |
}); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="myId"></div> | |
<script id="jsbin-javascript"> | |
alert(myId.id); // --> myId |
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
func = (c = d) -> | |
"hello #{c}" | |
func1 = (c) -> | |
c ?= d | |
"hello #{c}" | |
func2 = (c) -> | |
c = d unless c? | |
"hello #{c}" |
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
odd = (num) -> | |
unless typeof num is 'number' | |
throw "#{num} is not a number" | |
unless num is Math.round num | |
throw "#{num} is not an integer" | |
unless num > 0 | |
throw "#{num} is not positive" | |
num % 2 is 1 | |
test = (v) -> |
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 loadScript(url, callback){ | |
var script = document.createElement ("script") ; | |
script.type = "text/javascript"; | |
if (script.readyState){ //IE | |
script.onreadystatechange = function(){ | |
if (script.readyState == "loaded" || script.readyState == "complete"){ | |
script.onreadystatechange = null; | |
callback(); | |
} |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<style> | |
body { | |
text-align: center; | |
} | |
.wrapper { |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<style> | |
body { | |
text-align: center; | |
} | |
.wrapper { |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<style> | |
body { | |
text-align: center; | |
} | |
.wrapper { |