请教,jQuery自定义扩展方法私有函数问题

winzond 2019-07-17 11:37:17
$.fn.testExtsMthdsPrvtVar = function (options) {
this.read = function () {
return this.settings;
}
if (typeof options == "object") {
this.settings = $.extend({ name: "张三" }, options || {});
} else if (options == "read") {
this.read();
}
}

let zs = $();
zs.testExtsMthdsPrvtVar({});
console.log(zs.testExtsMthdsPrvtVar("read"));

输出的是undefined,请问怎样才能达到输出{ name: "张三" }的目的呢?
...全文
119 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
scscms太阳光 2019-07-18
  • 打赏
  • 举报
回复
$.fn.testExtsMthdsPrvtVar = function (options) { this.read = function () { return this.settings; } if (typeof options == "object") { this.settings = $.extend({ name: "张三" }, options || {}); } else if (options == "read") { return this.read(); } }

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧