私は奇妙な方法で構築されたJSファイルに出くわしました:
var modal = (function(){
var method = {};
// Center the modal in the viewport
method.center = function () {};
// Open the modal
method.open = function (settings) {};
// Close the modal
method.close = function () {};
return method;
}());
関数を「モーダル」オブジェクトにラップする部分は理解していますが、すべての関数をバインドmethod
して最後に返すのはなぜですか?