Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从javascript对象执行公共方法_Javascript_Jquery - Fatal编程技术网

如何从javascript对象执行公共方法

如何从javascript对象执行公共方法,javascript,jquery,Javascript,Jquery,我在访问外部文件中定义的函数时遇到问题,请给出一条建议如何修复以下问题 页面代码: var be = null; $(document) .ready(function() { be = $("#article-content") .bootstrapeditor({ // }); // how can I call public method wizardWorkedOut

我在访问外部文件中定义的函数时遇到问题,请给出一条建议如何修复以下问题

页面代码:

  var be = null;
    $(document)
      .ready(function() {
        be = $("#article-content")
          .bootstrapeditor({
            //
          });

        // how can I call public method wizardWorkedOut from 
        // https://jsfiddle.net/f0rza/572q21fj/ ?
      });

外部脚本:

! 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);

您可以通过创建BootstrapEditor的实例进行访问,如下所示

 //Creating an instance of bootstrapeditor
 var instance = new be.__proto__.bootstrapeditor.Constructor()
 //Access the methods in the prototype
 instance.wizardWorkedOut()

您必须创建一个
BootstrapEditor
的实例,然后您可以调用它的方法,例如
wizardWorkedOut
,即使在初始化对象之后,我也会得到一个错误: