Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

javascript - What does $ mean in 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());

}

 };

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

$li and $container are just variable names, named like that so the programmer knows they are jQuery extended objects.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...