mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05:00
Altered bound functions with do to just use call(this) rather than binding.
This commit is contained in:
@@ -108,7 +108,7 @@
|
|||||||
],
|
],
|
||||||
Do: [
|
Do: [
|
||||||
o("DO Code", function() {
|
o("DO Code", function() {
|
||||||
return new Call($2, $2.params);
|
return $2["do"]();
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
Code: [
|
Code: [
|
||||||
|
|||||||
@@ -1048,6 +1048,14 @@
|
|||||||
Code.prototype.traverseChildren = function(crossScope, func) {
|
Code.prototype.traverseChildren = function(crossScope, func) {
|
||||||
return crossScope ? Code.__super__.traverseChildren.call(this, crossScope, func) : undefined;
|
return crossScope ? Code.__super__.traverseChildren.call(this, crossScope, func) : undefined;
|
||||||
};
|
};
|
||||||
|
Code.prototype["do"] = function() {
|
||||||
|
if (this.bound) {
|
||||||
|
this.bound = false;
|
||||||
|
return new Call(new Value(this, [new Accessor(new Literal('call'))]), [new Literal('this')].concat(this.params));
|
||||||
|
} else {
|
||||||
|
return new Call(this, this.params);
|
||||||
|
}
|
||||||
|
};
|
||||||
return Code;
|
return Code;
|
||||||
})();
|
})();
|
||||||
exports.Param = (function() {
|
exports.Param = (function() {
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ grammar =
|
|||||||
]
|
]
|
||||||
|
|
||||||
Do: [
|
Do: [
|
||||||
o "DO Code", -> new Call $2, $2.params
|
o "DO Code", -> $2.do()
|
||||||
]
|
]
|
||||||
|
|
||||||
# The **Code** node is the function literal. It's defined by an indented block
|
# The **Code** node is the function literal. It's defined by an indented block
|
||||||
|
|||||||
@@ -889,6 +889,14 @@ exports.Code = class Code extends Base
|
|||||||
# Short-circuit `traverseChildren` method to prevent it from crossing scope boundaries
|
# Short-circuit `traverseChildren` method to prevent it from crossing scope boundaries
|
||||||
# unless `crossScope` is `true`.
|
# unless `crossScope` is `true`.
|
||||||
traverseChildren: (crossScope, func) -> super(crossScope, func) if crossScope
|
traverseChildren: (crossScope, func) -> super(crossScope, func) if crossScope
|
||||||
|
|
||||||
|
# Automatically calls the defined function.
|
||||||
|
do: ->
|
||||||
|
if @bound
|
||||||
|
@bound = no
|
||||||
|
new Call(new Value this, [new Accessor new Literal 'call']
|
||||||
|
[new Literal 'this'].concat this.params)
|
||||||
|
else new Call this, this.params
|
||||||
|
|
||||||
#### Param
|
#### Param
|
||||||
|
|
||||||
|
|||||||
@@ -355,3 +355,8 @@ do (v1) ->
|
|||||||
v2 = 4
|
v2 = 4
|
||||||
ok v1 is 1
|
ok v1 is 1
|
||||||
ok v2 is 4
|
ok v2 is 4
|
||||||
|
|
||||||
|
cxt = {}
|
||||||
|
val = null
|
||||||
|
(-> do => val = this).call cxt
|
||||||
|
ok val is cxt
|
||||||
|
|||||||
Reference in New Issue
Block a user