Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$.fn.myFunction = function(options) { var options = $.extend({}, $.fn.myFunction.defaults, options); $.fn.myFunction.defaults = { var1: 123, var2: 987 } }
我需要在 myFunction 之外获取 var1 (= 123) ... 怎么做?
您只是希望能够从任何地方访问该值?
console.log($.fn.myFunction.defaults.var1) // 123
在这种特殊情况下,
var default1 = $.fn.myFunction.defaults.va1;
但是没有通用的(与插件无关的)方法可以做到这一点。