Heim  >  Artikel  >  Web-Frontend  >  这是定义的方法还是属性?_html/css_WEB-ITnose

这是定义的方法还是属性?_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:40:461103Durchsuche

var pageController = {
    init: function () {
        this.featureBtnInit();          //功能按钮初始化
    },
    featureBtnInit: function () {  //功能按钮
        var $featureBtn = $("#featureBtn");
        var openClass = "btn-feature-open";
        if (!$featureBtn[0])return this;
        $featureBtn.on("click", function () {
            if(!$featureBtn.hasClass(openClass)){
                $featureBtn.addClass(openClass);
            }else{
                $featureBtn.removeClass(openClass);
            }
        });
        $(document).on("touchstart", function (e) {
            if (!$(e.target).parents("#featureBtn")[0]) {
                $featureBtn.removeClass(openClass);
            }
        });
    }
}


/* ================== 页面开始 ================== */
$(function () {
    pageController.init(); 
})

问题:
“init”和“featureBtnInit”这是定义的属性还是方法???    
为什么要定义2个方法,定义一个Function函数就可以搞定啊,这样定义有什么好处???


回复讨论(解决方案)

http://www.cnblogs.com/kuikui/archive/2013/07/14/3190381.html

1、属性。 但是属性是方法。

2、这样定义结构清晰。方法可以进行不同的调用。

不是两个方法,只是可以调用属性的方法而已。。。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn