我有以下 Javascript 函数:
function MyPseudoClass(){
this.initConfirmationSheet = function initConfirmationSheet(myDiv){
//foo
//bar
//etc.
}
//foo
function setUpGUI(){
var myDiv = document.getElementById(DivForDiagram);
myDiv.innerHTML = ""; //Clear contents of DIV for subsequent Diagram drawing.
confSheetDiagramRef = GO(go.Diagram, DivForDiagram, // the DIV HTML element
{
initialContentAlignment: go.Spot.Center,
initialAutoScale:go.Diagram.Uniform,
"toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom
});
confSheetDiagramRef.initialContentAlignment = go.Spot.Center;
confSheetDiagramRef.undoManager.isEnabled = true;
confSheetDiagramRef.isReadOnly = true;
var texttemplate = GO(go.Node, "Horizontal",
GO(go.TextBlock,
new go.Binding("text", "text"),
new go.Binding("font", "fontType"),
new go.Binding("textAlign", "textAlign")
),
new go.Binding("location", "shapePosition"),
new go.Binding("angle", "rotation"),
new go.Binding("width", "width"),
new go.Binding("height", "height")
)
var imagetemplate = GO(go.Node, "Horizontal",
GO(go.Picture,
new go.Binding("text", "text"),
new go.Binding("font", "fontType"),
new go.Binding("location", "position"),
new go.Binding("angle", "rotation"),
new go.Binding("width", "width"),
new go.Binding("source", "text"),
new go.Binding("height", "height"),
new go.Binding("maxSize", "bounds")
)
)
var templmap = new go.Map("string", go.Node);
templmap.add("text", texttemplate);
templmap.add("image", imagetemplate);
confSheetDiagramRef.nodeTemplateMap = templmap;
confSheetDiagramRef.addDiagramListener('InitialLayoutCompleted', function(e){
alert("in listener!");
generateImages(700,100);
})
}
function generateImages(){
//foo
//bar
this.initConfirmationSheet('myDiv');
}
}
MyPseudoClass
在以下上下文中调用:
nextConf = new MyPseudoClass(this);
nextConf.setInfo(confInfoVO, true, PasseDInEventDateTime_str, ParentRef.TicketPrintLayout, false);
nextConf.printAllConfirmations(ParentRef.DivName, numConfirmations);
我收到以下错误: 类型错误:this.initConfirmationSheet 不是函数
我不确定为什么第一个函数不在第二个函数的范围内。
特别是因为第一个函数可用于 MyPseudoClass
内的另一个函数。 :
this.thirdFunction = function thirdFunction(divName){
this.initConfirmationSheet(divName);
}
是因为这个函数被定义了,还是附加到了这个类的实例上?与 this.functionName
未定义的另一个相反?
最佳答案
您不受 MyPseudoClass
的约束例如,当您从外部来源调用 <a onclick="myPseudoClassObj.generateImages()>
时,您可以通过执行以下操作强制绑定(bind)所有调用
this.generateImages = function(){
//foo
//bar
this.initConfirmationSheet('myDiv');
}.bind(this);
关于javascript - TypeError : this. initConfirmationSheet 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33247945/