[英]How can I execute public method from javascript object
I have a problem with access to the function defined in external file, please give a piece of advice how can I fix following. 我在访问外部文件中定义的功能时遇到问题,请提出一些建议,该如何解决以下问题。
Page code: 页面代码:
var be = null;
$(document)
.ready(function() {
be = $("#article-content")
.bootstrapeditor({
//
});
// how can I call public method wizardWorkedOut from
// https://jsfiddle.net/f0rza/572q21fj/ ?
});
https://jsfiddle.net/f0rza/jhotm90r/ https://jsfiddle.net/f0rza/jhotm90r/
External script: 外部脚本:
! function($) {
var BootstrapEditor = function(element, options) {
this.canDemolishEditor = true;
};
BootstrapEditor.prototype.wizardWorkedOut = function() {
this.wizardWorkedOut();
};
BootstrapEditor.prototype = {
constructor: BootstrapEditor,
wizardWorkedOut: function() {
console.log('bootstrap-editor instance: wizardWorkedOut');
this.canDemolishEditor = true;
}
};
$.fn.bootstrapeditor = function(option, val) {
return this.each(function() {
var $this = $(this),
data = $this.data("bootstrapeditor"),
options = typeof option === "object" && option;
if (!data) {
$this.data("bootstrapeditor",
(data = new BootstrapEditor(this, $.extend({},
$.fn.bootstrapeditor.defaults, options))));
}
if (typeof option === "string") data[option](val);
});
};
$.fn.bootstrapeditor.defaults = {
onRender: function(date) {
return "";
}
};
$.fn.bootstrapeditor.Constructor = BootstrapEditor;
}(window.jQuery);
https://jsfiddle.net/f0rza/572q21fj/ https://jsfiddle.net/f0rza/572q21fj/
You can access by creating an instance of BootstrapEditor, as shown below. 您可以通过创建BootstrapEditor的实例进行访问,如下所示。
//Creating an instance of bootstrapeditor
var instance = new be.__proto__.bootstrapeditor.Constructor()
//Access the methods in the prototype
instance.wizardWorkedOut()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.