Last active
August 19, 2017 10:17
-
-
Save ozw-sei/5055933 to your computer and use it in GitHub Desktop.
CoffeeScript入門 ref: http://qiita.com/ozw_sei/items/b45e316fced8aec9a97e
This file contains 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
CoffeeScript はプログラミング言語のひとつである。コードはJavaScript のコードに変換される。 | |
Ruby や Python、Haskell から影響を受けたシンタックスシュガーの導入により、JavaScript に比べ簡潔さと可読性を向上させたほか、配列内包 (Array comprehensions) やパターンマッチといった機能を追加している。 | |
CoffeeScript により、パフォーマンスを下げることなく、より短いコードでプログラムを記述することができる (JavaScript に比べ 1/3 程度の行数が削減できる)。 |
This file contains 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
/* | |
JavaScript流 | |
Hello,World | |
*/ | |
//変数つくったー! | |
var helloWorld = "Hello,World"; | |
//1文字以上かチェーーック | |
if( helloWorld.length > 1){ | |
//アラーーート | |
alert(helloWorld); | |
} | |
This file contains 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
### | |
Coffee流 | |
Hello,World | |
### | |
#変数つくった | |
helloWorld = "Hello,World" | |
#1文字以上かチェック | |
if helloWorld.length > 1 | |
alert helloWorld |
This file contains 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
#配列つくります | |
container0 = [1,2,3] | |
#行列に似せた配列つくります | |
container1 = [ | |
1,2, | |
3,4, | |
5,6] | |
#辞書つくります {key:val} | |
a2 = {"ScreenWidth":480,"ScreenHeight":800} | |
### | |
辞書内辞書 | |
ゴジラ | |
身長:50メートル | |
体重:2万トン | |
ガメラ | |
身長:60メートル | |
体重:80トン | |
### | |
a3 = | |
"Godzilla": | |
"height":50 | |
"weight":20000 | |
"Gamera": | |
"height":60 | |
"weight":80 | |
This file contains 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
helloWorld = -> | |
alert 'Hello,World' | |
#引数 | |
test = (name) -> | |
alert "my name is #{name}" | |
This file contains 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
### | |
alertとprintを読み替えてください(何度もアラートしたらだるい) | |
なんか、良い出力あったら教えてください・・・ | |
### | |
//1~100走査 | |
for i in [1..100] | |
fizz = i % 3 == 0 | |
buzz = i % 5 == 0 | |
print i | |
if fizz and buzz | |
alert 'fizzBuzz' | |
if fizz | |
alert 'fizz' | |
if buzz | |
alert 'buzz' |
This file contains 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 buzz, fizz, i, _i; | |
for (i = _i = 1; _i <= 100; i = ++_i) { | |
fizz = i % 3 === 0; | |
buzz = i % 5 === 0; | |
print(i); | |
if (fizz && buzz) { | |
print('fizzBuzz'); | |
} | |
if (fizz) { | |
print('fizz'); | |
} | |
if (buzz) { | |
print('buzz'); | |
} | |
} |
This file contains 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
class Snake | |
#コンストラクタ | |
constructor: (@name) -> | |
#メソッド | |
move: (metor) -> | |
alert " moved #{metor}m." | |
#継承 | |
class Python extends Snake | |
move: -> | |
#基底クラスのメンバ呼び出し | |
alert @name + "is Move" | |
class Boa extends Snake | |
move: -> | |
alert @name +"is Move" | |
ProgramingLanguage = new Python 'Python!' | |
DangerSnake = new Boa 'Boa!" | |
ProgramingLanguage.move() | |
DangerSnake.move() | |
This file contains 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 Boa, DangerSnake, ProgramingLanguage, Python, Snake, | |
__hasProp = {}.hasOwnProperty, | |
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | |
Snake = (function() { | |
function Snake(name) { | |
this.name = name; | |
} | |
Snake.prototype.move = function(metor) { | |
return alert(" moved " + meters + "m."); | |
}; | |
return Snake; | |
})(); | |
Python = (function(_super) { | |
__extends(Python, _super); | |
function Python() { | |
Python.__super__.constructor.apply(this, arguments); | |
} | |
Python.prototype.move = function() { | |
return alert(this.name + "is Move"); | |
}; | |
return Python; | |
})(Snake); | |
Boa = (function(_super) { | |
__extends(Boa, _super); | |
function Boa() { | |
Boa.__super__.constructor.apply(this, arguments); | |
} | |
Boa.prototype.move = function() { | |
return alert(this.name(+"is Move")); | |
}; | |
return Boa; | |
})(Snake); | |
ProgramingLanguage = new Python('Python!'); | |
DangerSnake = new Boa('Boa!'); | |
ProgramingLanguage.move(); | |
DangerSnake.move(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment