我想在我的主干视图中包含一个有用的函数库。我正在使用require.js。我的图书馆看起来像:
define(function (require) {
"use strict";
console.log('in the useful');
var $ = require('jquery');
function myFunction()
{
alert("Hello World!");
}
});
视图是这样的:
define(function (require) {
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
UsefulFuncs = require('app/utils/useful_func'),
tpl = require('text!tpl/Register.html'),
template = _.template(tpl),
errors = [],
Backbone = require('backbone');
return Backbone.View.extend({
initialize: function() {
this.render();
},
render: function () {
this.$el.html(template());
return this;
},
events: {
'submit .register-form' : 'onSubmit',
},
onSubmit: function(e) {
//UsefulFuncs.myFunction();
myFunction();
},
});
});
但是当我点击“提交”时,我得到“myFunction is not defined”。当我尝试 UsefulFuncs.myFunction();
那么如何在主干视图中访问我的函数库呢?