我是新來的鈦Studio和我試圖從Appcelerator的按照教程鈦工作室需要()JavaScript的模塊
然而,當我創建Person.js(在app /控制器的文件夾),並嘗試通過
var Person = require("Person");
var don = new Person('Don','Thorp');
var donsName = don.fullName(); // "Don Thorp"
使用它在我的index.js文件中我遇到了錯誤的fullNmae()沒有定義(它在Person.js定義)。
有沒有人有類似的問題?請幫助我,謝謝!
的Person.js代碼
function Person(firstName,lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.fullName = function() {
return this.firstName+' '+this.lastName;
};
module.exports = Person;
的錯誤信息是:
[ERROR] : TiExceptionHandler: (main) [196,196] ----- Titanium Javascript Runtime Error -----
[ERROR] : TiExceptionHandler: (main) [0,196] - In alloy/controllers/index.js:1,69
[ERROR] : TiExceptionHandler: (main) [0,196] - Message: Uncaught TypeError: Object #<Controller> has no method 'fullName'
[ERROR] : TiExceptionHandler: (main) [0,196] - Source: xtend(s,s.__views);var l=require("Person"),c=new l("Don","Thorp");c.fullName()
[ERROR] : V8Exception: Exception occurred at alloy/controllers/index.js:1: Uncaught TypeError: Object #<Controller> has no method 'fullName'
您應該可以在開發人員工具中進行調試。 –
您能否分享錯誤日誌和您的Person.js代碼。 –
您是否可以包含Person的代碼? –