CoffeeScript
is a little language that compiles into JavaScript. Underneath all those
awkward braces and semicolons, ang JavaScript ay palging mayroong gorgeous
object model at its heart. Ang CoffeScript ay ang mas pinagandang paraan at
pinadaling paraan ng JavaScript. Ikino-compile nito ang code one-to-one into
the equivalent JavaScript, and there is no interpretation at runtime. Pwede
mong gamitin ang anumang existing JavaScript library seamlessly from
CoffeeScript.
The
coffee command takes the following options:
-c, --compile Kino-compile
nito ang .coffee script into .javascipt file of the s ame name
-i, --interactive Launch an interactive CoffeeScript session to try short
snippets. Identical to calling coffee with
no arguments.
-o, --output [DIR] Write out all
compiled JavaScript files into the specified directory. Use in conjunction with --compile or --watch.
-j, --join [FILE] Before
compiling, concatenate all scripts together in the order they were passed, and
write them into the specified file. Useful for building large projects.
-w, --watch Watch
files for changes, rerunning the specified command kapag ang isang file e
naguupdate.
-p, --print Instead
of writing out the JavaScript as a file, pwede mo xang iprint directly sa
stdout.
-l, --lint Once
na naiinstall na ang JavaSctipt Lint, maaari itong magamit para macheck ang
compilation ng CoffeeScript file
-s, --stdio Pipe
in CoffeScript to STDIN and get back JavaScript over STDOUT. Good for use with
the processes written in other languages. Halimbawa: cat src/cake.coffee |
coffee -sc
-e, --eval Nagko-compile
at nagpi-print ng little snippet ng CoffeeScript directly from the command
line. Halimbawa: coffee –e “console.log num for num in
[10..1]”
-r, --require Nilo-load ang library before magcompile o
mag-execute ng script. Can be used to hook in to the compiler.
-b, --bare Nagko-compile ng JavaScript ng wala ang
top-level function safety wrapper.
-t, --tokens Instead of parsing
the CoffeeScript, just lex it, tapos iprint out ang token stream.
-n, --nodes Imbis na magcompile
ng CoffeeScript, just lex and parse it, tapos iprint out ang parse tree.
-nodejs The node executable ahs some useful options you can
set, such as –debug, --debug-brk and –max-stack-size. Ito ang ginagamit to
forward options directly to Node.JavaScript.
First,the basics: CoffeeScript uses
significant whitespace to delimit blocks of code. Hindimo na kailangang gumamit
ng semicolon to terminate expressions, ending the line will do just as well
(although semicolons can still be used to fit multiple expressions onto a
single line). Then, instead na gumamit ng curly braces to surround blocks of
code in functions, if-statement, switch, and try/catch, indentation na lang ang
gamitin.
Hindi mo na kailngang gumamit ng parentheses
to invoke a function if you’re passing arguments. The implicit call wraps
forward to the end of the line or block expression.
Functions are defined by an optional list of
parameters in parentheses, an arrow, and the function body. Tapos, ganito ang
empty function: ->. It also
have default values for arguments.
Override the default value by passing a non-null argument.
If, Else, Unless and
Conditional AssignmentIf/else statement
naman ay pdeng isulat o icode without the use of parentheses and curly braces.
As with functions and other block expressions, multi-line conditionals are
delimited by indentation. There’s also a handy postfix form, with the if or unless at the end.
CoffeScript can compile if statements into JavaScript expressions, gamit
ang ternary operator when possible, and closure wrapping otherwise.
Most of the loops na isinususlat sa
CoffeeScript will be comprehensions over array, objects and ranges.
Comprehensions replace for loops, with optionalguard clauses and the value of
the current array index. Unlike sa loops, ang array comprehension ay
expreesion, and can be returned and assigned.
Ang natatnging low-level loop na napoprovide
ng CoffeeScript ay ang while loop. Ang
main difference nito sa JavaScript is that the while loop can be used as an expression, returning an array containing the
result of each iteration through the loop.
Once na gagamit ka ng JavaScript loop para
maggenerate ng functions, it’s common to insert a closure wrapper para maensure
na ang loop variables ay closed over, then all generated functions don’t just
share the final values. Nagpo-provide naman ang CoffeScript ng do keyword,
which immediately invokes a passed function, forwarding any arguments.
by: Camille Abigail M. Rollan
200910643
0 comments:
Post a Comment