本文介绍了$ j在jQuery中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了一段代码。它如下:

I recently came across a piece of code. It is as follows:

      var myFeature = {

'config' : {
    'container' : $('#myFeature')
},

'init' : function(config) {

    if (config && typeof(config) == 'object') {
        $.extend(myFeature.config, config);
    }

    myFeature.$container = myFeature.config.container;

    myFeature.$sections = myFeature.$container.
        find('ul.sections > li');

    myFeature.$section_nav = $('<ul/>').
        attr('id','section_nav').
        prependTo(myFeature.$container);

    myFeature.$item_nav = $('<ul/>').
        attr('id','item_nav').
        insertAfter(myFeature.$section_nav);

    myFeature.$content = $('<div/>').
        attr('id','content').
        insertAfter(myFeature.$item_nav);

    myFeature.buildSectionNav(myFeature.$sections);
    myFeature.$section_nav.find('li:first').click();

    myFeature.$container.find('ul.sections').hide();

    myFeature.initialized = true;

},


'buildSectionNav' : function($sections) {

    $sections.each(function() {

        var $section = $(this);

        $('<li/>').
            text($section.find('h2:first').text()).
            appendTo(myFeature.$section_nav).
            data('section', $section).
            click(myFeature.showSection);
    });

},

'buildItemNav' : function($items) {

    $items.each(function() {
        var $item = $(this);

        $('<li/>').
            text($item.find('h3:first').text()).
            appendTo(myFeature.$item_nav).
            data('item', $item).
            click(myFeature.showContentItem);

    });

},

'showSection' : function() {

    var $li = $(this);

    myFeature.$item_nav.empty();
    myFeature.$content.empty();

    var $section = $li.data('section');

    $li.addClass('current').
        siblings().removeClass('current');

    var $items = $section.find('ul li');

    myFeature.buildItemNav($items);

    myFeature.$item_nav.find('li:first').click();

},

'showContentItem' : function() {

    var $li = $(this);

    $li.addClass('current').
        siblings().removeClass('current');

    var $item = $li.data('item');

    myFeature.$content.html($item.html());

}

 };

我知道$('#myFeature'),$(this)的含义。
但是$ li和myFeature。$ container是什么意思?
它们是某种类型的变量吗?
如果是这样,myFeature的范围是多少。$ container?因为它没有使用var声明,它是全局的吗?

I know what $('#myFeature'), $(this) means.But what does $li and myFeature.$container mean?Are they some type of variables?If so, what is the scope of myFeature.$container? since it is not declared using var, is it global?

推荐答案

这只是公共变量,$被授权成为一个var名称和作者只想用$ at开头命名他的变量。关于myFeature。$ container这只是myFeature对象的一个​​属性,所以它与myFeature的范围相同

this is just commons variables, $ is authorized to be part of a var name and the author just like to name his vars with a $ at start. Regarding myFeature.$container this is just a property of the myFeature object so it's the same scope of myFeature

这篇关于$ j在jQuery中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 09:12