在下面例子中为什么在PageSwitch中又定义了名为PageSwitch的函数var PageSwitch = (function () { function PageSwitch(element, options) { // deep copy this.settings = $.extend(true, $.fn.PageSwitch.defaults, options || {}); this.element = element; this.init(); }})
4 回答
已采纳
Suber丶林
TA贡献75条经验 获得超180个赞
var PageSwitch = (function() {...});
// 因为括号内外都没有操作符,那上面代码等同于
var PageSwitch = function() {...};
// 也就是最基本的把一个function赋值给PageSwitch变量
// 本人还是不提倡酱紫写,因为JavaScript有变量提升机制,所以会增加阅读难度
// 提倡正规字面量形式
function PageSwitch() {...}添加回答
举报
0/150
提交
取消
