我有这个视图模型
var MyVM = function() {
var self = this;
// i wrote private function like this
function getNames() {
//some logic
}
//i want to call function inside this code
$("body").on("onTrigger", (evt, msg) => {
getNames();
});
}
,但不调用函数getNames()
。如何调用私有函数?
答案 0 :(得分:1)
尝试像这样更改代码,
var names = {
getNames : function(){
//some logic
}}
然后以这种方式调用该函数:
names.getNames();
或创建MyVM的对象并像这样调用:
MyVM names = new MyVM();
names.getNames();