【发布时间】:2026-01-05 01:10:01
【问题描述】:
这是我的咖啡脚本代码。
class Hello
constructor: ->
@greetings()
this.greetings()
greetings()
greetings: ->
alert 'hello world'
new Hello
这段代码翻译成
var Hello;
Hello = (function() {
function Hello() {
this.greetings();
this.greetings();
greetings();
}
Hello.prototype.greetings = function() {
return alert('hello world');
};
return Hello;
})();
new Hello;
在咖啡脚本代码的第三种情况下,我既没有使用@,也没有使用this。我假设咖啡脚本会使用隐含的 this,但事实并非如此。
我做了一个快速的谷歌搜索,但没有得到任何结果。那么任何人都可以确认coffeescript不支持隐式this。
【问题讨论】:
标签: coffeescript