Programming language/javascript

coffeescript 문법

hello-world 2018. 3. 22. 15:05
728x90
반응형

아 진짜 어쩌다 일로써 Framerjs를 쓰게 되었는데......

Framerjs 자체도 짜증이 나지만 ...Framerjs를 사용하려면 CoffeScript로 코딩해야 하는데

  짜증이.. ㅠㅠ  할 것도 많은데 이걸 익히자니 너무 부담스럽다요새 한창 Angular에 빠져 살고 있었는데.. 그리고 Python과 Django 해야 하는데...

적응되니 나름 편하다. 파이썬 장고 스터디는 달나라로 고고싱~ㅋ


아 ~~


짜증은 짜증이고 일은 일이기에...( 돈은 벌어야 하니까 ) 

까먹기 전에 생각나는 것 위주로 정리해 본다. 


Javascript

if(x===3){

alert x

}else if(x===4){
alert x - 5
}else{
alert x - 3

}



var major; major = 'Computer Science'; if (major == null) { signUpForClass('Introduction to Wines'); }


Coffeescript

if x is 3
alert x
else if x is 4
alert x - 5
else
alert x - 3



major = 'Computer Science' unless major? signUpForClass 'Introduction to Wines'

javascript


// Assignment:
var cubes, list, math, num, number, opposite, race, square;

number = 42;
opposite = true;

if (opposite) {
// Conditions:
number = -42;
}

// Functions:
square = function(x) {
return x * x;
};

// Arrays:
list = [1, 2, 3, 4, 5];

// Objects:
math = {
root: Math.sqrt,
square: square,
cube: function(x) {
return x * square(x);
}
};

// Splats:
race = function(winner, ...runners) {
return print(winner, runners);
};

if (typeof elvis !== "undefined" && elvis !== null) {
// Existence:
alert("I knew it!");
}

// Array comprehensions:
cubes = (function() {
var i, len, results;
results = [];
for (i = 0, len = list.length; i < len; i++) {
num = list[i];
results.push(math.cube(num));
}
return results;
})();


위의 자바스크립트를 커피스크립트로 변환된 것


다른건 바로 알겠는데 if 구문과 for 문 이 정말 헷갈린다...머리가 받아들이고 싶지 않은듯.. ㅠㅠ


특히 !== 표현은 isnt 라니!!!!!!!!!!

추가로 3항 연산자는 if  then else 로 표현할 수 있다.

# Assignment: number = 42 opposite = true # Conditions: number = -42 if opposite # Functions: square = (x) -> x * x # Arrays: list = [1, 2, 3, 4, 5] # Objects: math = root: Math.sqrt square: square cube: (x) -> x * square x # Splats: race = (winner, runners...) -> print winner, runners # Existence: alert "I knew it!" if elvis? # Array comprehensions: cubes = (math.cube num for num in list)


COFFEESCRIPT

JAVASCRIPT

is===
isnt!==
not!
and&&
or||
true, yes, offtrue
false, no, offfalse



728x90
반응형