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

WBOY
Release: 2016-06-24 11:40:46
Original
1105 people have browsed it

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、这样定义结构清晰。方法可以进行不同的调用。

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!