Reputation: 97
I made an Alloy project trying to understand how to work with separate JS files.
So far i tried to make Functions and Classes with no success.
Here's an example of a Class that i tried to make.
index.js
var Label = require("test");
label = new Label();
$.index.add(label);
$.index.open();
test.js
//Create Function
function Label() {
// Create label
var label = Ti.UI.createLabel({
text:"qweqwe"
});
// Return label
return label;
}
module.exports = Label;
When i try to compile i get this error
Can you please demonstrate the proper structure of a Function or Class that i can later use from an other js file using module.exports or exports.
Upvotes: 0
Views: 77
Reputation: 3866
Please read the Alloy QuickStart about views, requiring controllers and widgets. what you are doing is mixing classic and alloy with no (clear) reason, which is not considere best practice.
Upvotes: 1
Reputation: 973
The error shows that, the file path of test module is wrong. Add your test.js file in lib folder as shown below, and try
it works for me. also refer CommonJs module in Titanium
Upvotes: 2