Javascript: 无法执行初始化函数
Javascript: unable to execute init function
我正在开发 groupdocs 查看器,想重新创建这样的插件,
groupdocs 代码如下
(function ($) {
var methods = {
init: function (options) {
debugger
var defaults = {
};
options = $.extend(defaults, options);
}
}
$.fn.viewer = function (method) {
console.log(method)
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method' + method + ' does not exist on jQuery.viewer');
}
};
}(jQuery));
这段代码工作正常,但是当我像下面这样创建自定义代码时,
(function ($) {
var methods = {
init: function (options) {
debugger
var defaults = {
};
options = $.extend(defaults, options);
}
}
$.fn.secondFunction = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method' + method + ' does not exist on jQuery.viewer');
}
};
}(jQuery));
secondFunction
和事件初始化:未执行,
我的代码可能有什么问题
您的代码运行良好。打开检查器并 运行 按下下面的 运行 按钮,你会看到它暂停在调试器语句上。
(function ($) {
var methods = {
init: function (options) {
debugger
var defaults = {
};
options = $.extend(defaults, options);
}
}
$.fn.secondFunction = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method' + method + ' does not exist on jQuery.viewer');
}
};
}(jQuery));
$().secondFunction();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
我正在开发 groupdocs 查看器,想重新创建这样的插件,
groupdocs 代码如下
(function ($) {
var methods = {
init: function (options) {
debugger
var defaults = {
};
options = $.extend(defaults, options);
}
}
$.fn.viewer = function (method) {
console.log(method)
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method' + method + ' does not exist on jQuery.viewer');
}
};
}(jQuery));
这段代码工作正常,但是当我像下面这样创建自定义代码时,
(function ($) {
var methods = {
init: function (options) {
debugger
var defaults = {
};
options = $.extend(defaults, options);
}
}
$.fn.secondFunction = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method' + method + ' does not exist on jQuery.viewer');
}
};
}(jQuery));
secondFunction
和事件初始化:未执行,
我的代码可能有什么问题
您的代码运行良好。打开检查器并 运行 按下下面的 运行 按钮,你会看到它暂停在调试器语句上。
(function ($) {
var methods = {
init: function (options) {
debugger
var defaults = {
};
options = $.extend(defaults, options);
}
}
$.fn.secondFunction = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method' + method + ' does not exist on jQuery.viewer');
}
};
}(jQuery));
$().secondFunction();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>