我學習的CoffeeScript我有這樣的代碼:爲什麼coffescript創建這個封閉
class Person
constructor: (@firstName, @lastName) ->
sayHi:() ->
return "Hi, I'm #{@firstName} #{@lastName}"
,並生成這段JavaScript代碼:
// Generated by CoffeeScript 1.10.0
(function() {
var Person;
Person = (function() {
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.sayHi = function() {
return "Hi, I'm " + this.firstName + " " + this.lastName;
};
return Person;
})();
}).call(this);
我想創建class
的實例,但因爲它在關閉內部我不知道該怎麼做?
你應該提到你正在使用'node.js'? –
我沒有使用'node'。只是'npm'用於安裝一些軟件包,但它現在只是前端應用程序 – Pablo
我想對此運行jasmine測試,但是當我需要js文件時,Person是未定義的,因爲它在關閉中 – Pablo