基于调用原型的javascript函数

基于调用原型的javascript函数,javascript,performance,prototype,Javascript,Performance,Prototype,我想调用函数this.createVertextTemplate'text;间距=-5;',30,20,'Text','Text',true,但我是基于原型的JavaScript的初学者,任何人都可以指导我如何调用上述函数 我的密码在这里 Sidebar.prototype.addGeneralPalette = function(expand) { this.addPalette('general', mxResources.get('general'), expand || true

我想调用函数this.createVertextTemplate'text;间距=-5;',30,20,'Text','Text',true,但我是基于原型的JavaScript的初学者,任何人都可以指导我如何调用上述函数

我的密码在这里

Sidebar.prototype.addGeneralPalette = function(expand)
{
    this.addPalette('general', mxResources.get('general'), expand || true, mxUtils.bind(this, function(content)
    {


        //myT.appendChild(this.createVertexTemplate('text;spacingTop=-5;', 30, 20, 'Text', 'Text', true));
        content.appendChild(this.createVertexTemplate('swimlane;whiteSpace=wrap', 200, 200, 'Container', 'Container', true));
        content.appendChild(this.createVertexTemplate('whiteSpace=wrap', 120, 60, '', 'Rectangle', true));
        content.appendChild(this.createVertexTemplate('rounded=1;whiteSpace=wrap', 120, 60, '', 'Rounded Rectangle', true));
        content.appendChild(this.createVertexTemplate('text;spacingTop=-5;', 30, 20, 'Text', 'Text', true));
        content.appendChild(this.createVertexTemplate('ellipse;whiteSpace=wrap', 80, 80, '', 'Circle', true));
        content.appendChild(this.createVertexTemplate('ellipse;shape=doubleEllipse;whiteSpace=wrap', 80, 80, '', 'Double Ellipse', true));
        content.appendChild(this.createVertexTemplate('shape=ext;double=1;whiteSpace=wrap', 120, 60, 'Double Rectangle', 'Double Rectangle', true));
        content.appendChild(this.createVertexTemplate('shape=ext;double=1;rounded=1;whiteSpace=wrap', 120, 60, 'Double\nRounded Rectangle', 'Double Rounded Rectangle', true));
        content.appendChild(this.createVertexTemplate('shape=process;whiteSpace=wrap', 120, 60, '', 'Process', true));
        content.appendChild(this.createVertexTemplate('shape=parallelogram;whiteSpace=wrap', 120, 60, '', 'Parallelogram', true));
        content.appendChild(this.createVertexTemplate('shape=trapezoid;whiteSpace=wrap', 120, 60, '', 'Trapezoid', true));
        content.appendChild(this.createVertexTemplate('shape=document;whiteSpace=wrap', 120, 80, '', 'Document', true));
        content.appendChild(this.createVertexTemplate('triangle;whiteSpace=wrap', 60, 80, '', 'Triangle', true));
        content.appendChild(this.createVertexTemplate('rhombus;whiteSpace=wrap', 80, 80, '', 'Rhombus', true));
        content.appendChild(this.createVertexTemplate('shape=hexagon;whiteSpace=wrap', 120, 80, '', 'Hexagon', true));
        content.appendChild(this.createVertexTemplate('shape=step;whiteSpace=wrap', 120, 80, '', 'Step', true));
        content.appendChild(this.createVertexTemplate('shape=cylinder;whiteSpace=wrap', 60, 80, '', 'Cylinder', true));
        content.appendChild(this.createVertexTemplate('shape=tape;whiteSpace=wrap', 120, 100, '', 'Tape', true));
        content.appendChild(this.createVertexTemplate('shape=xor;whiteSpace=wrap', 60, 80, '', 'Exclusive Or', true));
        content.appendChild(this.createVertexTemplate('shape=or;whiteSpace=wrap', 60, 80, '', 'Or', true));
        content.appendChild(this.createVertexTemplate('shape=cube;whiteSpace=wrap', 120, 80, '', 'Cube', true));
        content.appendChild(this.createVertexTemplate('shape=note;whiteSpace=wrap', 80, 100, '', 'Note', true));
        content.appendChild(this.createVertexTemplate('shape=folder;whiteSpace=wrap', 120, 120, '', 'Folder', true));
        content.appendChild(this.createVertexTemplate('shape=card;whiteSpace=wrap', 60, 80, '', 'Card', true));
        content.appendChild(this.createVertexTemplate('shape=message;whiteSpace=wrap', 60, 40, '', 'Message', true));
        content.appendChild(this.createVertexTemplate('shape=actor;whiteSpace=wrap', 40, 60, '', 'Actor 1', true));
        content.appendChild(this.createVertexTemplate('icon;image=' + this.gearImage, 60, 60, 'Image', 'Image', false));
        content.appendChild(this.createVertexTemplate('whiteSpace=wrap;label;image=' + this.gearImage, 140, 60, 'Label', 'Label', true));
        content.appendChild(this.createVertexTemplate('shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top', 30, 60, '', 'Actor 2', true));
        content.appendChild(this.createVertexTemplate('ellipse;shape=cloud;whiteSpace=wrap', 120, 80, '', 'Cloud', true));
        content.appendChild(this.createVertexTemplate('line', 160, 10, '', 'Horizontal Line', true));
        content.appendChild(this.createVertexTemplate('line;direction=south', 10, 160, '', 'Vertical Line', true));

        content.appendChild(this.createEdgeTemplate('edgeStyle=none;endArrow=none;', 100, 100, '', 'Line', true));
        content.appendChild(this.createEdgeTemplate('edgeStyle=none;endArrow=none;dashed=1;', 100, 100, '', 'Dashed Line', true));
        content.appendChild(this.createEdgeTemplate('edgeStyle=none;endArrow=none;dashed=1;dashPattern=1 4', 100, 100, '', 'Dotted Line', true));
        content.appendChild(this.createEdgeTemplate('edgeStyle=none', 100, 100, '', 'Connection', true));

        var cells = [new mxCell('', new mxGeometry(0, 0, 100, 100), 'curved=1')];
        cells[0].geometry.setTerminalPoint(new mxPoint(0, 100), true);
        cells[0].geometry.setTerminalPoint(new mxPoint(100, 0), false);
        cells[0].geometry.points = [new mxPoint(100, 100), new mxPoint(0, 0)];
        cells[0].geometry.relative = true;
        cells[0].edge = true;
        content.appendChild(this.createEdgeTemplateFromCells(cells, 100, 100, 'Curve', true));

        content.appendChild(this.createEdgeTemplate('edgeStyle=elbowEdgeStyle;elbow=horizontal', 100, 100, '', 'Horizontal Elbow', true));
        content.appendChild(this.createEdgeTemplate('edgeStyle=elbowEdgeStyle;elbow=vertical', 100, 100, '', 'Vertical Elbow', true));
        content.appendChild(this.createEdgeTemplate('edgeStyle=entityRelationEdgeStyle', 100, 100, '', 'Entity Relation', true));
        content.appendChild(this.createEdgeTemplate('edgeStyle=segmentEdgeStyle', 100, 100, '', 'Manual Line', true));
        content.appendChild(this.createEdgeTemplate('edgeStyle=orthogonalEdgeStyle', 100, 100, '', 'Automatic Line', true));
        content.appendChild(this.createEdgeTemplate('shape=link', 100, 100, '', 'Link', true));
        content.appendChild(this.createEdgeTemplate('arrow', 100, 100, '', 'Arrow', true));
    }));
};

您正在将回调函数传递给SidebaraddGeneralPalette,当调用该函数时,this变量不再指向Sidebar的当前实例。您需要做以下两件事之一:

var that = this;

this.addPalette(..., function(content) {
    that.createVertexTemplate(...);
});
或:


试试这个var obj=new侧边栏;obj.createVertexTemplate
this.addPalette(..., function(content) {
    this.createVertexTemplate(...);
}.bind(this));