我有我的这样的JavaScript代码。里面,我有一个init()函数,并在该函数中我有一个选项JSON对象,并在该对象中,我有一个函数定义为objectselected()。我如何调用该函数在一个按钮单击事件从外部范围调用私有/嵌套的JavaScript函数
我已经试过这样WorkFlow.init()。options.Objectselected(),但它不工作,
var WorkFlow = {
connectionData: [],
selectedTouchpoints: [],
init: function() {
var options = {
palleteId: "myPaletteElement",
elementId: "playAreaContainer",
TextStoreList: ['One', 'Two', 'Three'],
LinkTextStoreList: $('#drpLinkType option').map(function() {
return this.text;
}).get(),
shapeList: ['RoundedRectangle', 'Circle', 'Rectangle', 'Ellipse', 'Square', 'Diamond', 'Card', 'Database'],
diagramUpdate: function (e) {
},
objectSelected: function (e) {
},
linkUpdate: function (e) {
},
initialize: function() {
}
myGraph = new Graph(options);
options.initialize();
},
}
如何调用该函数。
因为'options'是在其范围内私有变量,你不必给它的外部访问。还要注意这个问题与jQuery或JSON无关。 – Utkanos
'init()'不会返回任何东西,所以你不能执行'init()。options' –
你不能在json字符串中使用函数 – madalinivascu