我正在努力理解下面的代码。我知道这是一个自我调用功能。最后,当文档准备就绪时,将调用该方法methodDraw.init(function() { if(!window.methodDraw) window.methodDraw = function($) { var svgCanvas; var Editor = {}; var is_ready = false; var curConfig = { canvas_expansion: 1, dimensions: [580,400], initFill: {color: 'fff', opacity: 1}, initStroke: {width: 1.5, color: '000', opacity: 1}, initOpacity: 1, imgPath: 'images/', extPath: 'extensions/', jGraduatePath: 'lib/jgraduate/images/', extensions: [], initTool: 'select', wireframe: false, colorPickerCSS: false, gridSnapping: false, gridColor: "#000", baseUnit: 'px', snappingStep: 10, showRulers: (svgedit.browser.isTouch()) ? false : true, show_outside_canvas: false, no_save_warning: true, initFont: 'Helvetica, Arial, sans-serif' }; var curPrefs = {}; //$.extend({}, defaultPrefs); var customHandlers = {}; Editor.curConfig = curConfig; Editor.tool_scale = 1; Editor.setConfig = function(opts) { $.extend(true, curConfig, opts); if(opts.extensions) { curConfig.extensions = opts.extensions; } } Editor.init = function() { // For external openers (function() { console.log("inside editor.init") // let the opener know SVG Edit is ready var w = window.opener; if (w) { try { var methodDrawReadyEvent = w.document.createEvent("Event"); methodDrawReadyEvent.initEvent("methodDrawReady", true, true); w.document.documentElement.dispatchEvent(methodDrawReadyEvent); } catch(e) {} } })(); }; })();我不明白的是,methodDraw如何等同于编辑器?如何打电话?在控制台中,方法绘制消息后跟编辑器消息。还是我完全搞错了。请耐心等待我,因为我刚刚开始使用jQuery。methodDraw.initEditor.init
1 回答
慕盖茨4494581
TA贡献1850条经验 获得超11个赞
在此代码片段中,如果您仔细观察 ,它是一个函数,最后它将返回在整个函数体中配置和准备的对象实例,因此由于此实例对象已经具有 init 方法,因此您可以直接将调用链接到它,下面是一个小片段,以简单的方式演示它:window.methodDrawEditorwindow.methodDraw
let Editor = {};
Editor.init = () => {
console.log('Editor.init');
}
let InitializerObj = (() => {
return Editor;
})()
InitializerObj.init();
添加回答
举报
0/150
提交
取消