y=x^对函数y lnsinx在区间间[1/e,+∞)存在最值

函数求最值问题y=x^(1/x) x属于(0,正无穷)求函数在所给区间上的最值.请写出具体过程
y=x^(1/x) 两边取对数则,lny=1/xlnx求导得y'*1/y=-1/x^2lnx+1/x^2则y'=(-1/x^2lnx+1/x^2)*x^(1/x)则当y'=0时,lnx-1=0.x=e,当x>e,y'>0.单增.x<e,y'<0,单减所以可知在x=e处取得最小值.所以最小值为e^(1/e).无最大值
为您推荐:
扫描下载二维码已知了点坐标,易求得,的长,进而可将,的坐标代入抛物线中,求出待定系数的值,即可得出抛物线的解析式.根据,的坐标,易求得直线的解析式.由于,都是定值,则的面积不变,若四边形面积最大,则的面积最大;可过作轴的垂线,交于,轴于;易得的面积是与积的一半,可设出点的坐标,分别代入直线和抛物线的解析式中,即可求出的长,进而可得出四边形的面积与点横坐标间的函数关系式,根据所得函数的性质即可求出四边形的最大面积.本题应分情况讨论:过作轴的平行线,与抛物线的交点符合点的要求,此时,的纵坐标相同,代入抛物线的解析式中即可求出点坐标;将平移,令点落在轴(即点),点落在抛物线(即点)上;可根据平行四边形的性质,得出点纵坐标(,纵坐标的绝对值相等),代入抛物线的解析式中即可求得点坐标.
,;,;(分)过,,;解这个方程组,得抛物线的解析式为:(分)过点作轴分别交线段和轴于点,在中,令,得方程解这个方程,得,设直线的解析式为解这个方程组,得的解析式为:(分)设,(分)当时,有最大值此时四边形面积有最大值(分)如图所示,过点作轴交抛物线于点,过点作交轴于点,此时四边形为平行四边形,设解得,(分)平移直线交轴于点,交轴上方的抛物线于点,当时,四边形为平行四边形,设,,解得或,此时存在点和综上所述存在个点符合题意,坐标分别是,,.(分)
此题考查了二次函数解析式的确定,图形面积的求法,平行四边形的判定和性质,二次函数的应用等知识,综合性强,难度较大.
3830@@3@@@@二次函数综合题@@@@@@255@@Math@@Junior@@$255@@2@@@@二次函数@@@@@@51@@Math@@Junior@@$51@@1@@@@函数@@@@@@7@@Math@@Junior@@$7@@0@@@@初中数学@@@@@@-1@@Math@@Junior@@
第三大题,第5小题
第四大题,第7小题
第三大题,第9小题
第三大题,第7小题
第三大题,第8小题
第三大题,第8小题
第九大题,第1小题
第九大题,第1小题
第三大题,第9小题
第三大题,第8小题
第三大题,第9小题
第三大题,第7小题
求解答 学习搜索引擎 | 已知:如图,抛物线y=a{{x}^{2}}+3ax+c(a>0)与y轴交于C点,与x轴交于A,B两点,A点在B点左侧.点B的坐标为(1,0),OC=3BO.(1)求抛物线的解析式;(2)若点D是线段AC下方抛物线上的动点,求四边形ABCD面积的最大值;(3)若点E在x轴上,点P在抛物线上.是否存在以A,C,E,P为顶点且以AC为一边的平行四边形?若存在,求出点P的坐标;若不存在,请说明理由.CoffeeScript 中文
alert "Hello CoffeeScript!"
CoffeeScript 是一门编译到 JavaScript 的小巧语言.
在 Java 般笨拙的外表下, JavaScript 其实有着一颗华丽的心脏.
CoffeeScript 尝试用简洁的方式展示 JavaScript 优秀的部分.
CoffeeScript 的指导原则是: "她仅仅是 JavaScript".
代码一一对应地编译到 JS, 不会在编译过程中进行解释.
已有的 JavaScript 类库可以无缝地和 CoffeeScript 搭配使用, 反之亦然.
编译后的代码是可读的, 且经过美化, 能在所有 JavaScript 环境中运行,
并且应该和对应手写的 JavaScript 一样快或者更快.
sudo npm install -g coffee-script
左边是 CoffeeScript, 右边是编译后输出的 JavaScript.
opposite = true
number = -42 if opposite
square = (x) -& x * x
list = [1, 2, 3, 4, 5]
square: square
(x) -& x * square x
race = (winner, runners...) -&
print winner, runners
alert "I knew it!" if elvis?
cubes = (math.cube num for num in list)
var cubes, list, math, num, number, opposite, race, square,
__slice = [].
number = 42;
opposite = true;
if (opposite) {
number = -42;
square = function(x) {
return x *
list = [1, 2, 3, 4, 5];
root: Math.sqrt,
square: square,
cube: function(x) {
return x * square(x);
race = function() {
var runners,
winner = arguments[0], runners = 2 &= arguments.length ? __slice.call(arguments, 1) : [];
return print(winner, runners);
if (typeof elvis !== "undefined" && elvis !== null) {
alert("I knew it!");
cubes = (function() {
var _i, _len, _
_results = [];
for (_i = 0, _len = list. _i & _ _i++) {
num = list[_i];
_results.push(math.cube(num));
<div class='minibutton ok' onclick='javascript: var cubes, list, math, num, number, opposite, race, square,
__slice = [].
number = 42;
opposite =
if (opposite) {
number = -42;
square = function(x) {
return x *
list = [1, 2, 3, 4, 5];
root: Math.sqrt,
square: square,
cube: function(x) {
return x * square(x);
race = function() {
var runners,
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return print(winner, runners);
if (typeof elvis !== "undefined" && elvis !== null) {
alert("I knew it!");
cubes = (function() {
var _i, _len, _
_results = [];
for (_i = 0, _len = list. _i run: cubes
CoffeeScript 编译器本身,
命令行版本的 coffee 是一个实用的
不过并不依赖 Node,
而是能运行于任何 JavaScript 执行环境, 比如说在浏览器里(看上边的"试一试 CoffeeScript").
安装前你需要最新稳定版 ,
(Node Package Manager).
借助 npm 可以安装 CoffeeScript:
npm install -g coffee-script
(如果不想全局安装可以去掉 -g 选项.)
如果你希望安装 master 分支上最新的 CoffeeScript,
你可以从 克隆 CoffeeScript,
或直接下载.
还有通过 npm 方式安装 master 分支最新的 CoffeeScript 编译器:
npm install -g /jashkenas/coffee-script/tarball/master
或者你想将其安装到 /usr/local, 而不用 npm 进行管理,
进入 coffee-script 目录执行:
sudo bin/cake install
安装之后, 你应该可以运行 coffee 命令以执行脚本,
编译 .coffee 文件到 .js 文件, 和提供一个交互式的 REPL.
coffee 命令有下列参数:
-c, --compile
编译一个 .coffee 脚本到一个同名的 .js 文件.
随 JavaScript 文件一起生成 source maps. 并且在 JavaScript 里加上 sourceMappingURL 指令.
-i, --interactive
启动一个交互式的 CoffeeScript 会话用来尝试一些代码片段.
等同于执行 coffee 而不加参数.
-o, --output [DIR]
将所有编译后的 JavaScript 文件写到指定文件夹.
与 --compile 或 --watch 搭配使用.
-j, --join [FILE]
编译之前, 按参数传入顺序连接所有脚本到一起, 编译后写到指定的文件.
对于编译大型项目有用.
-w, --watch
监视文件改变, 任何文件更新时重新执行命令.
-p, --print
JavaScript 直接打印到 stdout 而不是写到一个文件.
-s, --stdio
将 CoffeeScript 传递到 STDIN 后从 STDOUT 获取 JavaScript.
对其他语言写的进程有好处. 比如:
cat src/cake.coffee | coffee -sc
-l, --literate
将代码作为 Literate CoffeeScript 解析.
只会在从 stdio 直接传入代码或者处理某些没有后缀的文件名需要写明这点.
-e, --eval
直接从命令行编译和打印一小段 CoffeeScript. 比如:
coffee -e "console.log num for num in [10..1]"
-b, --bare
编译到 JavaScript 时去掉.
-t, --tokens
不对 CoffeeScript 进行解析, 仅仅进行 lex, 打印出 token stream:
[IDENTIFIER square] [ASSIGN =] [PARAM_START (] ...
-n, --nodes
不对 CoffeeScript 进行编译, 仅仅 lex 和解析, 打印 parse tree:
Expressions
Value "square"
node 命令有一些实用的参数, 比如
--debug, --debug-brk, --max-stack-size,
和 --expose-gc. 用这个参数直接把参数转发到 Node.js.
重复使用 --nodejs 来传递多个参数.
编译一个 .coffee 文件的树形目录 src 到一个同级
.js 文件树形目录 lib:
coffee --compile --output lib/ src/
监视一个文件的改变, 每次文件被保证时重新编译:
coffee --watch --compile experimental.coffee
合并一组文件到单个脚本:
coffee --join project.js --compile src/*.coffee
从一个 one-liner 打印编译后的 JS:
coffee -bpe "alert i for i in [0..10]"
现在全部一起, 在你工作时监视和重复编译整个项目:
coffee -o lib/ -cw src/
运行 CoffeeScript REPL (Ctrl-D 来终止, Ctrl-V 激活多行):
Literate CoffeeScript
除了被作为一个普通的编程语言, CoffeeScript 也可以在 "literate" 模式下编写。
如果你以 .litcoffee 为扩展名命名你的文件, 你可以把它当作 Markdown 文件来编写 &
此文档恰好也是一份可执行的 CoffeeScript 代码,
编译器将会把所有的缩进块 (Markdown 表示源代码的方式) 视为代码, 其他部分则为注释.
Just for kicks, a little bit of the compiler is currently implemented in this fashion:
I'm fairly excited about this direction for the language, and am looking
forward to writing (and more importantly, reading) more programs in this style.
More information about Literate CoffeeScript, including an
这份手册所设计的结构, 方便从上往下进行阅读. 后边的章节使用前面介绍的语法和手法.
阅读这份手册需要对 JavaScript 比较熟悉.
以下所有的例子, CoffeeScript 源码将在左边显示, 并在右侧直接编译到 JavaScript.
很多例子可以通过点击右边的 run 按钮直接运行(代码有意义的话),
也可以通过点击左边的 load 按钮载入"试一试 CoffeeScript"的控制台.
首先, 一些基础, CoffeeScript 使用显式的空白来区分代码块.
你不需要使用分号 ; 来关闭表达式,
在一行的结尾换行就可以了(尽管分号依然可以用来把多行的表达式简写到一行里).
不需要再用花括号来
{ } 包裹代码快, 在 ,
当中使用缩进.
传入参数的时候, 你不需要再使用圆括号来表明函数被执行.
隐式的函数调用的作用范围一直到行尾或者一个块级表达式.
console.log sys.inspect object & console.log(sys.inspect(object));
函数通过一组可选的圆括号包裹的参数, 一个箭头, 一个函数体来定义.
一个空的函数像是这样:
square = (x) -& x * x
= (x) -& square(x) * x
square = function(x) {
return x *
cube = function(x) {
return square(x) *
loadrun: cube(5)
一些函数函数参数会有默认值, 当传入的参数的不存在 (null 或者 undefined)
时会被使用.
fill = (container, liquid = "coffee") -&
"Filling the #{container} with #{liquid}..."
fill = function(container, liquid) {
if (liquid == null) {
liquid = "coffee";
return "Filling the " + container + " with " + liquid + "...";
loadrun: fill("cup")
CoffeeScript 中对象和数组的字面量看起来很像在 JavaScript 中的写法.
如果单个属性被写在自己的一行里, 那么逗号是可以省略的.
类似, 对象可以用缩进替代花括号来声明.
song = ["do", "re", "mi", "fa", "so"]
singers = {Jagger: "Rock", Elvis: "Roll"}
bitlist = [
name: "Max"
name: "Ida"
var bitlist, kids, singers,
song = ["do", "re", "mi", "fa", "so"];
singers = {
Jagger: "Rock",
Elvis: "Roll"
bitlist = [1, 0, 1, 0, 0, 1, 1, 1, 0];
brother: {
name: "Max",
name: "Ida",
loadrun: song.join(" ... ")
JavaScript 里, 你不能使用不添加引号的保留字段作为属性名称, 比如 class.
CoffeeScript 里作为键出现的保留字会被识别并补上引号,
所以你不用有额外的操心(比如说, 使用 jQuery 的时候).
$('.account').attr class: 'active'
log object.class
$('.account').attr({
"class": 'active'
log(object["class"]);
CoffeeScript 编译器会考虑所有变量, 保证每个变量都在词法域里适当地被定义
& 你永远不需要自己去写 var.
changeNumbers = -&
inner = -1
outer = 10
inner = changeNumbers()var changeNumbers, inner,
outer = 1;
changeNumbers = function() {
inner = -1;
return outer = 10;
inner = changeNumbers();
loadrun: inner
注意所有变量的定义都被推到相关的顶层作用域, 也就是第一次出现的位置.
outer 在内层的函数里没有被重新定义, 因为它已经存在于作用域当中了.
同时, 内层函数里的 inner 不应该改变外部的同名的变量, 所以在这里有自己的声明.
其行为和 Ruby 的局部变量的作用域实际上是一致的.
由于你没有对 var 关键字的直接访问, 根据需要隐藏一个外部变量就很容易, 你只能引用它.
所以在写深层的嵌套的函数时, 注意不要意外用到和外部变量相同的名字.
尽管要说清楚会受到文档长度限制, 函数的所有 CoffeeScript 结果都被一个匿名函数包裹:
(function(){ ... })();
这层安全的封装, 加上自动生成的 var 关键字, 使得不小心污染全局命名空间很难发生.
如果你希望创建一个其他脚本也能使用的顶层变量, 那么将其作为赋值在 window 上,
或者在 CommonJS 里的 exports 上.
存在操作符(existential operator)可以帮你写出一个可靠的方式找到添加位置;
比如你的目标是同时满足 CommonJS 和浏览器: exports ? this
if/else 表达式可以不用圆括号和花括号就写出来.
就像函数和其他块级表达式那样, 多行的条件可以通过缩进来表明.
另外还有一个顺手的后缀形式, 在行尾使用 if or unless.
CoffeeScript 会尝试编译 if 语句到 JavaScript 表达式, 或者一个封装的闭包.
CoffeeScript 里不存在直白的三元表达式.
& 你只要在一行内使用普通的 if 语句.
mood = greatlyImproved if singing
if happy and knowsIt
clapsHands()
chaChaCha()
date = if friday then sue else jill
if (singing) {
mood = greatlyI
if (happy && knowsIt) {
clapsHands();
chaChaCha();
date = friday ? sue :
使用 JavaScript 的 arguments 对象是一种处理接收不定数量个参数的函数常用办法.
CoffeeScript 在函数定义和调用里提供了变参(splats) ... 的语法,
让不定个数的参数使用起来更愉悦一些.
gold = silver = rest = "unknown"
awardMedals = (first, second, others...) -&
silver = second
contenders = [
"Michael Phelps"
"Liu Xiang"
"Yao Ming"
"Allyson Felix"
"Shawn Johnson"
"Roman Sebrle"
"Guo Jingjing"
"Tyson Gay"
"Asafa Powell"
"Usain Bolt"
awardMedals contenders...
alert "Gold: " + gold
alert "Silver: " + silver
alert "The Field: " + rest
var awardMedals, contenders, gold, rest, silver,
__slice = [].
gold = silver = rest = "unknown";
awardMedals = function() {
var first, others,
first = arguments[0], second = arguments[1], others = 3 &= arguments.length ? __slice.call(arguments, 2) : [];
return rest =
contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
awardMedals.apply(null, contenders);
alert("Gold: " + gold);
alert("Silver: " + silver);
alert("The Field: " + rest);
load<div class='minibutton ok' onclick='javascript: var awardMedals, contenders, gold, rest, silver,
__slice = [].
gold = silver = rest = "unknown";
awardMedals = function() {
var first, others,
first = arguments[0], second = arguments[1], others = 3 run
你可以使用CoffeeScript将大多数的循环写成基于数组、对象或范围的推导式(comprehensions)。
推导式替代(编译为)for循环,并且可以使用可选的子句和数组索引值。
不同于for循环,数组的推导式是表达式,可以被返回和赋值。
eat food for food in ['toast', 'cheese', 'wine']
courses = ['greens', 'caviar', 'truffles', 'roast', 'cake']
menu i + 1, dish for dish, i in courses
foods = ['broccoli', 'spinach', 'chocolate']
eat food for food in foods when food isnt 'chocolate'
var courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _
_ref = ['toast', 'cheese', 'wine'];
for (_i = 0, _len = _ref. _i & _ _i++) {
food = _ref[_i];
eat(food);
courses = ['greens', 'caviar', 'truffles', 'roast', 'cake'];
for (i = _j = 0, _len1 = courses. _j & _len1; i = ++_j) {
dish = courses[i];
menu(i + 1, dish);
foods = ['broccoli', 'spinach', 'chocolate'];
for (_k = 0, _len2 = foods. _k & _len2; _k++) {
food = foods[_k];
if (food !== 'chocolate') {
eat(food);
推导式可以适用于其他一些使用循环的地方,例如each/forEach,
map,或者select/filter,例如:
shortNames = (name for name in list when name.length & 5)
如果你知道循环的开始与结束,或者希望以固定的跨度迭代,你可以在范围推导式中
指定开始与结束。
countdown = (num for num in [10..1])
var countdown,
countdown = (function() {
_results = [];
for (num = _i = 10; _i &= 1; num = --_i) {
_results.push(num);
load= 1; num = --_i) {
_results.push(num);
;alert(countdown);'>run: countdown
注意:上面的例子中我们展示了如何将推导式赋值给变量,CoffeeScript总是将
每个循环项收集到一个数组中。但是有时候以循环结尾的函数运行的目的就是
它们的副作用(side-effects)。这种情况下要注意不要意外的返回推导式的结果,
而是在函数的结尾增加一些有意义的返回值&例如true &
在推导式中使用by子句,可以实现以固定跨度迭代范围值:
evens = (x for x in [0..10] by 2)
推导式也可以用于迭代对象中的key和value。在推导式中使用of
来取出对象中的属性,而不是数组中的值。
yearsOld = max: 10, ida: 9, tim: 11
ages = for child, age of yearsOld
"#{child} is #{age}"
var age, ages, child, yearsO
yearsOld = {
ages = (function() {
_results = [];
for (child in yearsOld) {
age = yearsOld[child];
_results.push("" + child + " is " + age);
loadrun: ages.join(", ")
如果你希望仅迭代在当前对象中定义的属性,通过hasOwnProperty检查并
避免属性是继承来的,可以这样来写:
for own key, value of object
CoffeeScript仅提供了一种底层循环,即while循环。与JavaScript中的while
循环的主要区别是,在CoffeeScript中while可以作为表达式来使用,
而且可以返回一个数组,该数组包含每个迭代项的迭代结果。
if this.studyingEconomics
while supply & demand
sell() until supply & demand
lyrics = while num -= 1
"#{num} little monkeys, jumping on the bed.
One fell out and bumped his head."
var lyrics,
if (this.studyingEconomics) {
while (supply & demand) {
while (!(supply & demand)) {
lyrics = (function() {
_results = [];
while (num -= 1) {
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
load demand) {
while (!(supply > demand)) {
lyrics = (function() {
_results = [];
while (num -= 1) {
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
;alert(lyrics.join("
"));'>run: lyrics.join("
为了更好的可读性,until关键字等同于while not, loop关键字
等同于while true。
使用 JavaScript 循环生成函数的时候, 经常会添加一个闭包来包裹代码,
这样做目的是为了循环的变量被保存起来, 而不是所有生成的函数搜去访问最后一个循环的变量.
CoffeeScript 提供了一个 do 关键字, 用来直接调用跟在后边的函数, 并且传递需要的参数.
for filename in list
do (filename) -&
fs.readFile filename, (err, contents) -&
compile filename, contents.toString()var filename, _fn, _i, _
_fn = function(filename) {
return fs.readFile(filename, function(err, contents) {
return compile(filename, contents.toString());
for (_i = 0, _len = list. _i & _ _i++) {
filename = list[_i];
_fn(filename);
Range 也可以被用来展开数组的切片.
通过两个点号的写法 (3..6), range 会包含最后一个数据 (3, 4, 5, 6);
通过三个点号的写法 (3...6), range 不会包含最后一个数据 (3, 4, 5).
切片的索引位置存在不错的默认值. 前面的索引位置省略的话, 默认会是 0,
后面的索引位置被省略的话, 默认值是数组的大小.
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
= numbers[0..2]
= numbers[3...-2]
= numbers[-2..]
= numbers[..]
var copy, end, middle, numbers,
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
start = numbers.slice(0, 3);
middle = numbers.slice(3, -2);
end = numbers.slice(-2);
copy = numbers.slice(0);
loadrun: middle
同样的语法还可以用在数组的片段上赋值一些新的值, 进行拼接.
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers[3..6] = [-3, -4, -5, -6]
var numbers, _
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
[].splice.apply(numbers, [3, 4].concat(_ref = [-3, -4, -5, -6])), _
loadrun: numbers
注意 JavaScript 的 string 是不可变的, 所以不能用被拼接.
读者大概有注意到上面的代码 CoffeeScript 函数是不需要写 return 语句的, 但是也会返回最终的结果.
CoffeeScript 编译器会尽可能保证语言中所有的表达式都可以被当作表达式使用.
观察一下下面的函数, return 是怎样尽可能地插入到执行的分支当中的.
grade = (student) -&
if student.excellentWork
else if student.okayStuff
if student.triedHard then "B" else "B-"
eldest = if 24 & 21 then "Liz" else "Ike"var eldest,
grade = function(student) {
if (student.excellentWork) {
return "A+";
} else if (student.okayStuff) {
if (student.triedHard) {
return "B";
return "B-";
return "C";
eldest = 24 & 21 ? "Liz" : "Ike";
load 21 ? "Liz" : "Ike";
;alert(eldest);'>run: eldest
尽管函数总是会自动 return 其最终的值, 你可以在函数体前面显式地写上 (return value),
这个做法也是值得借鉴的, 前提是你明确你在做的事情是什么.
由于变量声明是生成在作用域顶部, 所以在表达式内部也可以写赋值, 即便是前面没写到过的变量.
six = (one = 1) + (two = 2) + (three = 3)
var one, six, three,
six = (one = 1) + (two = 2) + (three = 3);
loadrun: six
有些代码在 JavaScript 当中要写不少的语句, 而在 CoffeeScript 中只是表达式的一部分,
这些代码的编译结果会自动生成一个闭包. 这个写法很有用, 比如把列表解析的结果赋值给变量:
globals = (name for name of window)[0...10]var globals,
globals = ((function() {
_results = [];
for (name in window) {
_results.push(name);
})()).slice(0, 10);
loadrun: globals
结果是一些原来明确是语句的东西也可以像, 比如把 try/catch 语句直接传给函数调用:
nonexistent / undefined
catch error
"And the error is ... #{error}"
alert((function() {
return nonexistent / void 0;
} catch (_error) {
return "And the error is ... " +
有一些 JavaScript 语句是不能编译到表达式的对应的语义的, 比如 break, continue 和 return.
如果你的代码当中用到了它们, CoffeeScript 是不会尝试去进行转换的.
由于操作符 == 常常带来不准确的约束, 不容易达到效果, 而且跟其他语言当中意思不一致,
CoffeeScript 会把 == 编译为 ===, 把 != 变异为 !==.
此外, is 编译为 ===, 而 isnt 编译为 !==.
not 可以作为 ! 的 alias 使用.
逻辑操作方面, and 编译为 &&, 而 or 编译为 ||.
在 while, if/else, switch/when 的语句当中,
then 可以被用来分隔判断条件跟表达式, 这样就不用强制写换行或者分号了.
就像 , on 和 yes
跟 true 是一样的, 而 off 和 no 是布尔值 false.
unless 可以认为是 if 相反的版本.
this.property 简短的写法可以用 @property.
可以用 in 判断数据在数组中是否出现, 而 of
可以探测 JavaScript 对象的属性是否存在.
为了简化数学表达式, ** 可以用来表示乘方, // 表示整除, %%
提供数学的模运算(译注: true mathematical modulo?).
完整的列表:
CoffeeScriptJavaScript
true, yes, ontrue
false, no, offfalse
@, thisthis
inno JS equivalent
a ** bMath.pow(a, b)
a // bMath.floor(a / b)
a %% b(a % b + b) % b
launch() if ignition is on
volume = 10 if band isnt SpinalTap
letTheWildRumpusBegin() unless answer is no
if car.speed & limit then accelerate()
winner = yes if pick in [47, 92, 13]
print inspect "My name is #{@name}"
var volume,
if (ignition === true) {
if (band !== SpinalTap) {
volume = 10;
if (answer !== false) {
letTheWildRumpusBegin();
if (car.speed & limit) {
accelerate();
if (pick === 47 || pick === 92 || pick === 13) {
winner = true;
print(inspect("My name is " + this.name));
在 JavaScript 里检测一个变量的存在性有点麻烦.
if (variable) ... 比较接近答案, 但是对 `0` 不成立.
CoffeeScript 的存在性操作符 ? 除非是 null 或者 undefined, 否则都返回 true,
这大致是模仿 Ruby 当中的 nil?.
这也可以用在比 ||= 更安全的条件赋值当中, 有些情况你会需要处理数字跟字符串的.
solipsism = true if mind? and not world?
speed ?= 15
footprints = yeti ? "bear"
var footprints, solipsism,
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {
solipsism = true;
speed = 0;
if (speed == null) {
speed = 15;
footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear";
存在性操作符 ?. 的访问器的变体可以用来吸收链式属性调用中的 null.
数据可能是 null 或者 undefined 的情况下可以用这种写法替代访问器 ..
如果所有属性都存在, 那么你会得到想要的结果, 如果链式调用有问题, 会返回 undefined
而不是抛出 TypeError.
zip = lottery.drawWinner?().address?.zipcode
var zip, _
zip = typeof lottery.drawWinner === "function" ? (_ref = lottery.drawWinner().address) != null ? _ref.zipcode : void 0 : void 0;
吸收 null 数据的做法类似 Ruby 的
, 和 Groovy 的
JavaScript 的原型继承有点烧脑, 存在大量的类库用于在 JavaScript 的原型之上实现更清晰的 class 继承, 比如:
这些类库提供了语法糖, 但如果不是因为一些例外的话原生的继承完全是可用的, 例外比如:
很难调用 super(当前函数的原型上的实现), 很难正确设置原型链.
相比重复地设置函数的原型, CoffeeScript 提供了一个基础的 class 结构,
你可以在一个定义的表达式里完成命名 class, 定义父类, 赋值原型上的属性, 定义构造器.
构造函数被命名, 这对查看调用栈有更好的支持.
下面例子中的第一个类, this.constructor.name is "Animal".
class Animal
constructor: (@name) -&
move: (meters) -&
alert @name + " moved #{meters}m."
class Snake extends Animal
alert "Slithering..."
class Horse extends Animal
alert "Galloping..."
sam = new Snake "Sammy the Python"
tom = new Horse "Tommy the Palomino"
sam.move()
tom.move()
var Animal, Horse, Snake, sam, tom,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = } ctor.prototype = parent. child.prototype = new ctor(); child.__super__ = parent. return };
Animal = (function() {
function Animal(name) {
this.name =
Animal.prototype.move = function(meters) {
return alert(this.name + (" moved " + meters + "m."));
Snake = (function(_super) {
__extends(Snake, _super);
function Snake() {
return Snake.__super__.constructor.apply(this, arguments);
Snake.prototype.move = function() {
alert("Slithering...");
return Snake.__super__.move.call(this, 5);
})(Animal);
Horse = (function(_super) {
__extends(Horse, _super);
function Horse() {
return Horse.__super__.constructor.apply(this, arguments);
Horse.prototype.move = function() {
alert("Galloping...");
return Horse.__super__.move.call(this, 45);
})(Animal);
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");
sam.move();
tom.move();
如果你不喜欢用 class 的裁判法定义原型, CoffeeScript 提供了一些低级的方便写法.
extends 操作符可以用来恰当地定义任何一对构造函数的原型链;
用 :: 可以快速访问对象的原型;
super() 可以编译为一个父类上同名方法的调用.
String::dasherize = -&
this.replace /_/g, "-"
String.prototype.dasherize = function() {
return this.replace(/_/g, "-");
loadrun: "one_two".dasherize()
最后, class 定义是可执行的代码, 这样就可能进行元编程.
因为在 class 定义的上下文当中, this 是类对象本身(构造函数),
可以用 @property: value 赋值静态的属性,
也可以调用父类的方法: @attr 'title', type: 'text'.
CoffeeScript 实现 ECMAScript Harmony 的提议
语法, 这样从复杂的数组和对象展开数据会更方便一些.
当你把数组或者对象的字面量赋值到一个变量时, CoffeeScript 把等式两边都解开配对, 把右边的值赋值给左边的变量.
最简单的例子, 可以用来并行赋值:
theSwitch = 0
[theBait, theSwitch] = [theSwitch, theBait]
var theBait, theSwitch, _
theBait = 1000;
theSwitch = 0;
_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];
loadrun: theBait
用来处理函数多返回值也很方便.
weatherReport = (location) -&
[location, 72, "Mostly Sunny"]
[city, temp, forecast] = weatherReport "Berkeley, CA"
var city, forecast, temp, weatherReport, _
weatherReport = function(location) {
return [location, 72, "Mostly Sunny"];
_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];
loadrun: forecast
解构赋值可以用在深度嵌套的数组跟对象上, 取出深度嵌套的属性.
futurists =
sculptor: "Umberto Boccioni"
"Vladimir Burliuk"
"F.T. Marinetti"
address: [
"Via Roma 42R"
"Bellagio, Italy 22021"
{poet: {name, address: [street, city]}} = futurists
var city, futurists, name, street, _ref, _ref1;
futurists = {
sculptor: "Umberto Boccioni",
painter: "Vladimir Burliuk",
name: "F.T. Marinetti",
address: ["Via Roma 42R", "Bellagio, Italy 22021"]
_ref = futurists.poet, name = _ref.name, (_ref1 = _ref.address, street = _ref1[0], city = _ref1[1]);
loadrun: "name + "-" + street"
解构赋值还可以跟 splats 搭配使用.
tag = "&impossible&"
[open, contents..., close] = tag.split("")
var close, contents, open, tag, _i, _ref,
__slice = [].
tag = "&impossible&";
_ref = tag.split(""), open = _ref[0], contents = 3 &= _ref.length ? __slice.call(_ref, 1, _i = _ref.length - 1) : (_i = 1, []), close = _ref[_i++];
展开式(expansion)可以用于获取数组结尾的元素, 而不需要对中间过程的数据进行赋值.
它也可以用在函数参数的列表上.
text = "Every literary critic believes he will
outwit history and have the last word"
[first, ..., last] = text.split " "
var first, last, text, _
text = "Every literary critic believes he will outwit history and have the last word";
_ref = text.split(" "), first = _ref[0], last = _ref[_ref.length - 1];
loadrun: "first + " " + last"
解构赋值也可以用在 class 的构造器上, 从构造器配置对象赋值到示例属性上.
class Person
constructor: (options) -&
{@name, @age, @height} = options
tim = new Person age: 4
var Person,
Person = (function() {
function Person(options) {
this.name = options.name, this.age = options.age, this.height = options.
tim = new Person({
loadrun: tim.age
JavaScript 当中 this 关键字被动态地设定为当前函数挂载所在的对象上.
如果你把函数当作回调, 或者挂载到别的对象, 那么原先的 this 就丢失了.
如果你不了解这个行为,
If you're not familiar with this behavior,
对怪异模式做了很好的回顾.
Fat arrow =& 可以同时定义函数, 绑定函数的 this 到当前的值, 正是我们需要的.
这有助于在 Prototype 或者 jQuery 这种基于回调的类库当中使用,
用于创建迭代器函数传递给 each, 或者借助 bind 的事件处理器函数.
Fat arrow 定义的函数可以访问到他们创建位置的 this 对象的属性.
Account = (customer, cart) -&
@customer = customer
@cart = cart
$('.shopping_cart').bind 'click', (event) =&
@customer.purchase @cartvar A
Account = function(customer, cart) {
this.customer =
this.cart =
return $('.shopping_cart').bind('click', (function(_this) {
return function(event) {
return _this.customer.purchase(_this.cart);
})(this));
如果上边用的是 this,
@customer 会指向一个 DOM 元素的 undefined "customer" 属性,
然后强行调用上面的 purchase() 时会抛出一个异常.
对于类的定义, 实例创建的过程中 fat arrow 定义的方法会自动绑定到类的每个示例上去.
这个写法应该不会被用到, 但如果什么时候需要在 CoffeeScript 中穿插 JavaScript 片段的话,
你可以用反引号直接传进去.
hi = `function() {
return [document.title, "Hello JavaScript"].join(": ");
hi = function() {
return [document.title, "Hello JavaScript"].join(": ");
loadrun: hi()
JavaScript 里的 Switch 语句有点难看.
你需要在每个 case 写 break 防止自动进入默认的 case.
CoffeeScript 会阻止掉意外的 fall-through.
而且 switch 编译的结果会是可以带 return, 可以被用于赋值的表达式.
格式这样写: switch 判断条件,
when 然后子句, else 然后默认的 case.
就像 Ruby, CoffeeScript 里边 switch 语句对于每个子句可以带多个值.
任何一个值匹配的情况下, 子句就会执行.
switch day
when "Mon" then go work
when "Tue" then go relax
when "Thu" then go iceFishing
when "Fri", "Sat"
if day is bingoDay
go dancing
when "Sun" then go church
else go workswitch (day) {
case "Mon":
case "Tue":
go(relax);
case "Thu":
go(iceFishing);
case "Fri":
case "Sat":
if (day === bingoDay) {
go(bingo);
go(dancing);
case "Sun":
go(church);
Switch 语句也可以不写控制条件, 当作 if/else 调用链的一个更整洁的可选写法.
score = 76
grade = switch
when score & 60 then 'F'
when score & 70 then 'D'
when score & 80 then 'C'
when score & 90 then 'B'
var grade,
score = 76;
grade = (function() {
switch (false) {
case !(score & 60):
return 'F';
case !(score & 70):
return 'D';
case !(score & 80):
return 'C';
case !(score & 90):
return 'B';
return 'A';
Try/catch 语句基本上 JavaScript 的一样(尽管它们是表达式执行).
allHellBreaksLoose()
catsAndDogsLivingTogether()
catch error
print error
allHellBreaksLoose();
catsAndDogsLivingTogether();
} catch (_error) {
print(error);
} finally {
cleanUp();
CoffeeScript 从 Python 学习了
& 这样判断数值是否在某个范围内在写法上更容易.
cholesterol = 127
healthy = 200 & cholesterol & 60
var cholesterol,
cholesterol = 127;
healthy = (200 & cholesterol && cholesterol & 60);
load cholesterol && cholesterol > 60);
;alert(healthy);'>run: healthy
Ruby 风格的字符串替换也在 CoffeeScript 实现了. 双引号包裹的字符串允许数据替换, 用 #{ ... } 语法,
而单引号包裹的字符串仅仅是字面量.
author = "Wittgenstein"
= "A picture is a fact. -- #{ author }"
sentence = "#{ 22 / 7 } is a decent approximation of π"
var author, quote,
author = "Wittgenstein";
quote = "A picture is a fact. -- " +
sentence = "" + (22 / 7) + " is a decent approximation of π";
loadrun: sentence
CoffeeScript 支持多行字符串.
行与行会用一个空格拼接, 除非结尾用了反斜杠.
其中缩进会被忽略.
mobyDick = "Call me Ishmael. Some years ago --
never mind how long precisely -- having little
or no money in my purse, and nothing particular
to interest me on shore, I thought I would sail
about a little and see the watery part of the
mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...";
loadrun: mobyDick
块级的字符串可以用于书写格式化的或者对缩进敏感的文本(或者你只是不想转义单引号双引号).
代码块开始的位置的缩进层级会被保留, 用在后面的代码中, 所以这部分代码依然可以跟整体的代码一起对齐.
html = """
cup of coffeescript
html = "&strong&\n
cup of coffeescript\n&/strong&";
load<div class='minibutton ok' onclick='javascript:
html = "\n
cup of coffeescript\n";
;alert(html);'>run: html
块级的字符串用双引号, 跟普通的双引号字符串一样, 支持替换.
有时候你想把整块的注释传给生成的 JavaScript. 比如在文件顶部嵌入协议.
块级的注释, 仿照了块级字符串的语法, 将会在生成的代码当中保留.
类似块级的字符串跟注释, CoffeeScript 支持块级的正则 &
扩展了正则表达式, 可以忽略内部的空格, 可以包含注释和替换.
模仿了 Perl 的 /x 修饰符, CoffeeScript 的块级正则以 /// 为界,
让正则表达式获得了很大程度的可读性. 引用一下 CoffeeScript 源码:
OPERATOR = /// ^ (
| [-+*/%&&&|^!?=]=
| ([-+:])\1
| ([&|&&])\2=?
var OPERATOR;
OPERATOR = /^(?:[-=]&|[-+*\/%&&&|^!?=]=|&&&=?|([-+:])\1|([&|&&])\2=?|\?\.|\.{2,3})/;
Cake, and Cakefiles
CoffeeScript includes a (very) simple build system similar to
. Naturally,
it's called Cake, and is used for the tasks that build and test the CoffeeScript
language itself. Tasks are defined in a file named Cakefile, and
can be invoked by running cake [task] from within the directory.
To print a list of all the tasks and options, just type cake.
Task definitions are written in CoffeeScript, so you can put arbitrary code
in your Cakefile. Define a task with a name, a long description, and the
function to invoke when the task is run. If your task takes a command-line
option, you can define the option with short and long flags, and it will
be made available in the options object. Here's a task that uses
the Node.js API to rebuild CoffeeScript's parser:
fs = require 'fs'
option '-o', '--output [DIR]', 'directory for compiled code'
task 'build:parser', 'rebuild the Jison parser', (options) -&
require 'jison'
code = require('./lib/grammar').parser.generate()
= options.output or 'lib'
fs.writeFile "#{dir}/parser.js", codevar
fs = require('fs');
option('-o', '--output [DIR]', 'directory for compiled code');
task('build:parser', 'rebuild the Jison parser', function(options) {
require('jison');
code = require('./lib/grammar').parser.generate();
dir = options.output || 'lib';
return fs.writeFile("" + dir + "/parser.js", code);
If you need to invoke one task before another & for example, running
build before test, you can use the invoke function:
invoke 'build'. Cake tasks are a minimal way to expose your
CoffeeScript functions to the command line, so
If you need dependencies, or async callbacks, it's best to put them in your
code itself & not the cake task.
Source Maps
CoffeeScript 1.6.1 and above include support for generating source maps,
a way to tell your JavaScript engine what part of your CoffeeScript
program matches up with the code being evaluated. Browsers that support it
can automatically use source maps to show your original source code
in the debugger. To generate source maps alongside your JavaScript files,
pass the --map or -m flag to the compiler.
For a full introduction to source maps, how they work, and how to hook
them up in your browser, read the
"text/coffeescript" Script Tags
While it's not recommended for serious use, CoffeeScripts may be included
directly within the browser using &script type="text/coffeescript"&
tags. The source includes a compressed and minified version of the compiler
as extras/coffee-script.js. Include this file on a page with
inline CoffeeScript tags, and it will compile and evaluate them in order.
In fact, the little bit of glue script that runs "Try CoffeeScript" above,
as well as the jQuery for the menu, is implemented in just this way.
View source and look at the bottom of the page to see the example.
Including the script also gives you access to <pile()
so you can pop open Firebug and try compiling some strings.
The usual caveats about CoffeeScript apply & your inline scripts will
run within a closure wrapper, so if you want to expose global variables or
functions, attach them to the window object.
There are a number of excellent resources to help you get
started with CoffeeScript, some of which are freely available online.
is a brief 5-chapter introduction to CoffeeScript, written with great
clarity and precision by
is a reimagination of the excellent book
it had been written in CoffeeScript instead. Covers language features
as well as the functional and object oriented programming styles. By
is 's thorough
introduction to the language. By the end of the book, you'll have built
a fast-paced multiplayer word game, writing both the client-side and Node.js
portions in CoffeeScript.
is a new book by Michael Erasmus that covers CoffeeScript with an eye
towards real-world usage both in the browser (jQuery) and on the server
size (Rails, Node).
is a deep dive into CoffeeScript's semantics from simple functions up through
closures, higher-order functions, objects, classes, combinators, and decorators.
is a succinct and freely downloadable guide to building testable
applications with CoffeeScript and Jasmine.
is a new book from Packt Publishing that introduces CoffeeScript while
walking through the process of building a demonstration web application.
is a new book from Manning Publications that covers CoffeeScript syntax, composition techniques
and application development.
Screencasts
which combines 6 screencasts with in-browser coding to make learning fun.
The first level is free to try out.
is a 75-minute long screencast by .
Highly memorable for its animations which demonstrate transforming CoffeeScript
into the equivalent JS.
If you're looking for less of a time commitment, RailsCasts'
should have you covered, hitting all of the important notes about CoffeeScript
in 11 minutes.
can be found on GitHub. But just
to throw out few more:
github's ,
a friendly IRC robot that can perform any number of useful and useless tasks.
sstephenson's ,
a zero-configuration Rack server, with comprehensive annotated source.
technoweenie's ,
for Node.js.
a headless, full-stack, faux-browser testing library for Node.js.
jashkenas' , a port
library of helper functions.
stephank's , a remake of
the Bolo tank game for modern browsers.
josh's , a Node.js-powered
Use bin/coffee to test your changes,
bin/cake test to run the test suite,
bin/cake build to rebuild the CoffeeScript compiler, and
bin/cake build:parser to regenerate the Jison parser if you're
working on the grammar.
git checkout lib && bin/cake build:full is a good command to run when you're working
on the core language. It'll refresh the lib directory
(in case you broke something), build your altered compiler, use that to
rebuild itself (a good sanity test) and then run all of the tests. If
they pass, there's a good chance you've made a successful change.
Bug reports, feature proposals, and ideas for changes to the language belong here.
If you'd like to ask a question, the mailing list is a good place to get help.
If you've ever learned a neat CoffeeScript tip or trick, or ran into a gotcha & share it on the wiki.
The wiki also serves as a directory of handy
and general .
Perhaps your CoffeeScript-related question has been asked before. Check the FAQ first.
Is a very well done reverse JavaScript-to-CoffeeScript compiler. It's
not going to be perfect (infer what your JavaScript classes are, when
you need bound functions, and so on...) & but it's a great starting
point for converting simple scripts.
The CoffeeScript logo is available in Illustrator, EPS and PSD formats, for use
in presentations.
Web Chat (IRC)
Quick help and advice can usually be found in the CoffeeScript IRC room.
Join #coffeescript on irc.freenode.net, or click the
button below to open a webchat session on this page.
click to open #coffeescript
Change Log
Fixed a typo that broke node module lookup when running a script directly with the coffee binary.
When requiring CoffeeScript files in Node you must now explicitly register the compiler. This can be done with require 'coffee-script/register' or CoffeeScript.register(). Also for configuration such as Mocha's, use coffee-script/register.
Improved error messages, source maps and stack traces. Source maps now use the updated //# syntax.
Leading . now closes all open calls, allowing for simpler chaining syntax.
.click (e) -&
.fadeIn 'fast'
.addClass '.active'
.css 'background', 'white'
$('body').click(function(e) {
return $('.box').fadeIn('fast').addClass('.active');
}).css('background', 'white');
Added **, // and %% operators and ... expansion in parameter lists and destructuring expressions.
Multiline strings are now joined by a single space and ignore all indentation. A backslash at the end of a line can denote the amount of whitespace between lines, in both strings and heredocs. Backslashes correctly escape whitespace in block regexes.
Closing brackets can now be indented and therefore no longer cause unexpected error.
Several breaking compilation fixes. Non-callable literals (strings, numbers etc.) don't compile in a call now and multiple postfix conditionals compile properly. Postfix conditionals and loops always bind object literals. Conditional assignment compiles properly in subexpressions. super is disallowed outside of methods and works correctly inside for loops.
Formatting of compiled block comments has been improved.
No more -p folders on Windows.
The options object passed to CoffeeScript is no longer mutated.
The CoffeeScript REPL now remembers your history between sessions.
Just like a proper REPL should.
You can now use require in Node to load .coffee.md
Literate CoffeeScript files. In the browser,
text/literate-coffeescript script tags.
The old coffee --lint command has been removed. It was useful
while originally working on the compiler, but has been surpassed by
JSHint. You may now use -l to pass literate files in over
Bugfixes for Windows path separators, catch without naming
the error, and executable-class-bodies-with-
prototypal-property-attachment.
Source maps have been used to provide automatic line-mapping when
running CoffeeScript directly via the coffee command, and
for automatic line-mapping when running CoffeeScript directly in the
browser. Also, to provide better error messages for semantic errors
thrown by the compiler &
Improved support for mixed literate/vanilla-style CoffeeScript projects,
and generating source maps for both at the same time.
Fixes for 1.6.x regressions with overriding inherited bound
functions, and for Windows file path management.
The coffee command can now correctly fork()
both .coffee and .js files. (Requires Node.js 0.9+)
First release of . Pass the
--map flag to the compiler, and off you go. Direct all your
thanks over to .
Fixed a 1.5.0 regression with multiple implicit calls against an
indented implicit object. Combinations of implicit function calls
and implicit objects should generally be parsed better now &
but it still isn't good style to nest them too heavily.
.coffee.md is now also supported as a Literate CoffeeScript
file extension, for existing tooling.
.litcoffee remains the canonical one.
Several minor fixes surrounding member properties, bound methods and
super in class declarations.
First release of .
The CoffeeScript REPL is now based on the Node.js REPL, and should work
better and more familiarly.
Returning explicit values from constructors is now forbidden. If you want
to return an arbitrary value, use a function, not a constructor.
You can now loop over an array backwards, without having to manually
deal with the indexes: for item in list by -1
Source locations are now preserved in the CoffeeScript AST, although
source maps are not yet being emitted.
The CoffeeScript compiler now strips Microsoft's UTF-8 BOM if it
exists, allowing you to compile BOM-borked source files.
Fix Node/compiler deprecation warnings by removing registerExtension,
and moving from path.exists to fs.exists.
Small tweaks to splat compilation, backticks, slicing, and the
error for duplicate keys in object literals.
Due to the new semantics of JavaScript's strict mode, CoffeeScript no
longer guarantees that constructor functions have names in all runtimes.
for discussion.
Inside of a nested function inside of an instance method, it's now possible
to call super more reliably (walks recursively up).
Named loop variables no longer have different scoping heuristics than
other local variables. (Reverts #643)
Fix for splats nested within the LHS of destructuring assignment.
Corrections to our compile time strict mode forbidding of octal literals.
CoffeeScript now enforces all of JavaScript's Strict Mode early syntax
errors at compile time. This includes old-style octal literals,
duplicate property names in object literals, duplicate parameters in
a function definition, deleting naked variables, setting the value of
eval or arguments, and more.
See a full discussion at
The REPL now has a handy new multi-line mode for entering large
blocks of code. It's useful when copy-and-pasting examples into the
REPL. Enter multi-line mode with Ctrl-V. You may also now
pipe input directly into the REPL.
CoffeeScript now prints a Generated by CoffeeScript VERSION
header at the top of each compiled file.
Conditional assignment of previously undefined variables
a or= b is now considered a syntax error.
A tweak to the semantics of do, which can now be used to
more easily simulate a namespace: do (x = 1, y = 2) -> ...
Loop indices are now mutable within a loop iteration, and immutable
between them.
Both endpoints of a slice are now allowed to be omitted for consistency,
effectively creating a shallow copy of the list.
Additional tweaks and improvments to coffee --watch under
Node's "new" file watching API. Watch will now beep by default
if you introduce a syntax error into a watched script. We also now
ignore hidden directories by default when watching recursively.
Multiple improvements to coffee --watch and --join.
You may now use both together, as well as add and remove
files and directories within a --watch'd folder.
The throw statement can now be used as part of an expression.
Block comments at the top of the file will now appear outside of the
safety closure wrapper.
Fixed a number of minor 1.1.3 regressions having to do with trailing
operators and unfinished lines, and a more major 1.1.3 regression that
caused bound functions within bound class functions to have the incorrect
Ahh, whitespace. CoffeeScript's compiled JS now tries to space things
out and keep it readable, as you can see in the examples on this page.
You can now call super in class level methods in class bodies,
and bound class methods now preserve their correct context.
JavaScript has always supported octal numbers 010 is 8,
and hexadecimal numbers 0xf is 15, but CoffeeScript now
also supports binary numbers: 0b10 is 2.
The CoffeeScript module has been nested under a subdirectory to make
it easier to require individual components separately, without
having to use npm. For example, after adding the CoffeeScript
folder to your path: require('coffee-script/lexer')
There's a new "link" feature in Try CoffeeScript on this webpage. Use
it to get a shareable permalink for your example script.
The coffee --watch feature now only works on Node.js 0.6.0
and higher, but now also works properly on Windows.
Lots of small bug fixes from
Fixes for block comment formatting, ?= compilation, implicit calls
against control structures, implicit invocation of a try/catch block,
variadic arguments leaking from local scope, line numbers in syntax errors
following heregexes, property access on parenthesized number literals,
bound class methods and super with reserved names, a REPL overhaul,
consecutive compiled semicolons, block comments in implicitly called objects,
and a Chrome bug.
Bugfix release for classes with external constructor functions, see
issue #1182.
When running via the coffee executable, process.argv and
friends now report coffee instead of node.
Better compatibility with Node.js 0.4.x module lookup changes.
The output in the REPL is now colorized, like Node's is.
Giving your concatenated CoffeeScripts a name when using --join is now mandatory.
Fix for lexing compound division /= as a regex accidentally.
All text/coffeescript tags should now execute in the order they're included.
Fixed an issue with extended subclasses using external constructor functions.
Fixed an edge-case infinite loop in addImplicitParentheses.
Fixed exponential slowdown with long chains of function calls.
Globals no longer leak into the CoffeeScript REPL.
Splatted parameters are declared local to the function.
Fixed a lexer bug with Unicode identifiers. Updated REPL for compatibility
with Node.js 0.3.7. Fixed requiring relative paths in the REPL. Trailing
return and return undefined are now optimized away.
Stopped requiring the core Node.js "util" module for
back-compatibility with Node.js 0.2.5. Fixed a case where a
conditional return would cause fallthrough in a switch
statement. Optimized empty objects in destructuring assignment.
CoffeeScript loops no longer try to preserve block scope when functions
are being generated within the loop body. Instead, you can use the
do keyword to create a convenient closure wrapper.
Added a --nodejs flag for passing through options directly
to the node executable.
Better behavior around the use of pure statements within expressions.
Fixed inclusive slicing through -1, for all browsers, and splicing
with arbitrary expressions as endpoints.
The REPL now properly formats stacktraces, and stays alive through
asynchronous exceptions. Using --watch now prints timestamps as
files are compiled. Fixed some accidentally-leaking variables within
plucked closure-loops. Constructors now maintain their declaration
location within a class body. Dynamic object keys were removed.
Nested classes are now supported. Fixes execution context for naked
splatted functions. Bugfix for inversion of chained comparisons.
Chained class instantiation now works properly with splats.
0.9.5 should be considered the first release candidate for CoffeeScript 1.0.
There have been a large number of internal changes since the previous release,
many contributed from satyr's
dialect of CoffeeScript. Heregexes (extended regexes) were added. Functions
can now have default arguments. Class bodies are now executable code.
Improved syntax errors for invalid CoffeeScript. undefined now
works like null, and cannot be assigned a new value.
There was a precedence change with respect to single-line comprehensions:
result = i for i in list used to parse as result = (i for i in list)
by default ... it now parses as (result = i) for i in list.
CoffeeScript now uses appropriately-named temporary variables, and recycles
their references after use. Added require.extensions support for
Node.js 0.3. Loading CoffeeScript in the browser now adds just a
single CoffeeScript object to global scope.
Fixes for implicit object and block comment edge cases.
CoffeeScript switch statements now compile into JS switch
statements & they previously compiled into if/else chains
for JavaScript 1.3 compatibility.
Soaking a function invocation is now supported. Users of the RubyMine
editor should now be able to use --watch mode.
Specifying the start and end of a range literal is now optional, eg. array[3..].
You can now say a not instanceof b.
Fixed important bugs with nested significant and non-significant indentation (Issue #637).
Added a --require flag that allows you to hook into the coffee command.
Added a custom jsl.conf file for our preferred JavaScriptLint setup.
Sped up Jison grammar compilation time by flattening rules for operations.
Block comments can now be used with JavaScript-minifier-friendly syntax.
Added JavaScript's compound assignment bitwise operators. Bugfixes to
implicit object literals with leading number and string keys, as the subject
of implicit calls, and as part of compound assignment.
Bugfix release for 0.9.1. Greatly improves the handling of mixed
implicit objects, implicit function calls, and implicit indentation.
String and regex interpolation is now strictly #{ ... } (Ruby style).
The compiler now takes a --require flag, which specifies scripts
to run before compilation.
The CoffeeScript 0.9 series is considered to be a release candidate
for 1.0; let's give her a shakedown cruise. 0.9.0 introduces a massive
backwards-incompatible change: Assignment now uses =, and object
literals use :, as in JavaScript. This allows us to have implicit
object literals, and YAML-style object definitions. Half assignments are
removed, in favor of +=, or=, and friends.
Interpolation now uses a hash mark # instead of the dollar sign
$ & because dollar signs may be part of a valid JS identifier.
Downwards range comprehensions are now safe again, and are optimized to
straight for loops when created with integer endpoints.
A fast, unguarded form of object comprehension was added:
for all key, value of object. Mentioning the super keyword
with no arguments now forwards all arguments passed to the function,
as in Ruby. If you extend class B from parent class A, if
A has an extended method defined, it will be called, passing in B &
this enables static inheritance, among other things. Cleaner output for
functions bound with the fat arrow. @variables can now be used
in parameter lists, with the parameter being automatically set as a property
on the object & useful in constructors and setter functions.
Constructor functions can now take splats.
Quick bugfix (right after 0.7.1) for a problem that prevented coffee
command-line options from being parsed in some circumstances.
Block-style comments are now passed through and printed as JavaScript block
comments -- making them useful for licenses and copyright headers. Better
support for running coffee scripts standalone via hashbangs.
Improved syntax errors for tokens that are not in the grammar.
Official CoffeeScript variable style is now camelCase, as in JavaScript.
Reserved words are now allowed as object keys, and will be quoted for you.
Range comprehensions now generate cleaner code, but you have to specify by -1
if you'd like to iterate downward. Reporting of syntax errors is greatly
improved from the previous release. Running coffee with no arguments
now launches the REPL, with Readline support. The &- bind operator
has been removed from CoffeeScript. The loop keyword was added,
which is equivalent to a while true loop. Comprehensions that contain
closures will now close over their variables, like the semantics of a forEach.
You can now use bound function in class definitions (bound to the instance).
For consistency, a in b is now an array presence check, and a of b
is an object-key check. Comments are no longer passed through to the generated
JavaScript.
The coffee command will now preserve directory structure when
compiling a directory full of scripts. Fixed two omissions that were preventing
the CoffeeScript compiler from running live within Internet Explorer.
There's now a syntax for block comments, similar in spirit to CoffeeScript's heredocs.
ECMA Harmony DRY-style pattern matching is now supported, where the name
of the property is the same as the name of the value: {name, length}: func.
Pattern matching is now allowed within comprehension variables. unless
is now allowed in block form. until loops were added, as the inverse
of while loops. switch statements are now allowed without
switch object clauses. Compatible
with Node.js v0.1.95.
Upgraded CoffeeScript for compatibility with the new Node.js v0.1.90
Trailing commas are now allowed, a-la Python. Static
properties may be assigned directly within class definitions,
using @property notation.
Interpolation can now be used within regular expressions and heredocs, as well as
strings. Added the &- bind operator.
Allowing assignment to half-expressions instead of special ||=-style
operators. The arguments object is no longer automatically converted into
an array. After requiring coffee-script, Node.js can now directly
load .coffee files, thanks to registerExtension. Multiple
splats can now be used in function calls, arrays, and pattern matching.
String interpolation, contributed by
Since --run has been the default since 0.5.3, updating
--stdio and --eval to run by default, pass --compile
as well if you'd like to print the result.
Bugfix that corrects the Node.js global constants __filename and
__dirname. Tweaks for more flexible parsing of nested function
literals and improperly-indented comments. Updates for the latest Node.js API.
CoffeeScript now has a syntax for defining classes. Many of the core
components (Nodes, Lexer, Rewriter, Scope, Optparse) are using them.
Cakefiles can use optparse.coffee to define options for tasks.
--run is now the default flag for the coffee command,
use --compile to save JavaScripts. Bugfix for an ambiguity between
RegExp literals and chained divisions.
Added a compressed version of the compiler for inclusion in web pages as
extras/coffee-script.js. It'll automatically run any script tags
with type text/coffeescript for you. Added a --stdio option
to the coffee command, for piped-in compiles.
Improvements to null soaking with the existential operator, including
soaks on indexed properties. Added conditions to while loops,
so you can use them as filters with when, in the same manner as
comprehensions.
CoffeeScript 0.5.0 is a major release, While there are no language changes,
the Ruby compiler has been removed in favor of a self-hosting
compiler written in pure CoffeeScript.
@property is now a shorthand for this.property.
Switched the default JavaScript engine from Narwhal to Node.js. Pass
the --narwhal flag if you'd like to continue using it.
CoffeeScript 0.3 includes major syntax changes:
The function symbol was changed to
->, and the bound function symbol is now =>.
Parameter lists in function definitions must now be wrapped in parentheses.
Added property soaking, with the ?. operator.
Made parentheses optional, when invoking functions with arguments.
Removed the obsolete block literal syntax.
Added Python-style chained comparisons, the conditional existence
operator ?=, and some examples from Beautiful Code.
Bugfixes relating to statement-to-expression conversion, arguments-to-array
conversion, and the TextMate syntax highlighter.
The conditions in switch statements can now take multiple values at once &
If any of them are true, the case will run. Added the long arrow ==>,
which defines and immediately binds a function to this. While loops can
now be used as expressions, in the same way that comprehensions can. Splats
can be used within pattern matches to soak up the rest of an array.
Added ECMAScript Harmony style destructuring assignment, for dealing with
extracting values from nested arrays and objects. Added indentation-sensitive
heredocs for nicely formatted strings or chunks of code.
Axed the unsatisfactory ino keyword, replacing it with of for
object comprehensions. They now look like: for prop, value of object.
When performing a comprehension over an object, use ino, instead
of in, which helps us generate smaller, more efficient code at
compile time.
Added :: as a shorthand for saying .prototype.
The "splat" symbol has been changed from a prefix asterisk *, to
a postfix ellipsis ...
Added JavaScript's in operator,
empty return statements, and empty while loops.
Constructor functions that start with capital letters now include a
safety check to make sure that the new instance of the object is returned.
The extends keyword now functions identically to goog.inherits
in Google's Closure Library.
Arguments objects are now converted into real arrays when referenced.
Major release. Significant whitespace. Better statement-to-expression
conversion. Splats. Splice literals. Object comprehensions. Blocks.
The existential operator. Many thanks to all the folks who posted issues,
with special thanks to
for whitespace
and expression help.
Bugfix for running coffee --interactive and --run
from outside of the CoffeeScript directory. Bugfix for nested
function/if-statements.
Array slice literals and array comprehensions can now both take Ruby-style
ranges to specify the start and end. JavaScript variable declaration is
now pushed up to the top of the scope, making all assignment statements into
expressions. You can use \ to escape newlines.
The coffee-script command is now called coffee.
The official CoffeeScript extension is now .coffee instead of
.cs, which properly belongs to
Due to popular demand, you can now also use = to assign. Unlike
JavaScript, = can also be used within object literals, interchangeably
with :. Made a grammatical fix for chained function calls
like func(1)(2)(3)(4). Inheritance and super no longer use
__proto__, so they should be IE-compatible now.
The coffee command now includes --interactive,
which launches an interactive CoffeeScript session, and --run,
which directly compiles and executes a script. Both options depend on a
working installation of Narwhal.
The aint keyword has been replaced by isnt, which goes
together a little smoother with is.
Quoted strings are now allowed as identifiers within object literals: eg.
{"5+5": 10}.
All assignment operators now use a colon: +:, -:,
Fixed a bug with calling super() through more than one level of
inheritance, with the re-addition of the extends keyword.
Added experimental
support (as a Tusk package), contributed by
, including
bin/cs as a CoffeeScript REPL and interpreter.
New --no-wrap option to suppress the safety function
Added instanceof and typeof as operators.
Initial CoffeeScript release.

我要回帖

更多关于 y log2 cos2x 增区间 的文章

 

随机推荐