此代码存在于 swipe.js 库中。我正在尝试自定义它。返回之前的评论说“公开了 Swipe API”,但我不确定那是什么意思。
function Swipe(container, options) {
...
//everything that makes the library work, including a setup() function
...
//expose the Swipe API
return {
setup: function() {
setup();
},
slide: function(to, speed) {
// cancel slideshow
stop();
slide(to, speed);
},
prev: function() {
// cancel slideshow
stop();
prev();
},
next: function() {
// cancel slideshow
stop();
next();
},...some more stuff
}
返回值是数组吗?数组列表?举例来说,我实例化了一个新的滑动对象 window['aNewSwipeObject'] = Swipe($theDOMElement);
并且我像这样调用设置函数 window['aNewSwipeObject'].setup()
调用了什么 setup()? return上面的setup(),还是Swipe()函数return里面的匿名函数里面的setup()?
最佳答案
它返回一个对象字面量。对象中的每个键都是一个函数。
这通常用于创建函数的命名空间,通过将它们放在函数作用域中,函数将共享从命名空间继承的局部作用域。
例如,
var Namespace = (function() {
var helperFunction = function() { ... }
var localData = // ...
return {
publicFunction1 : function() { ... },
publicFunction2 : function() { ... },
publicFunction3 : function() { ... }
}
})();
关于javascript - 这个 swipe.js 函数返回了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17841273/