在Javascript中,这是什么意思底线? [英] In Javascript, what does this underscore mean?

查看:110
本文介绍了在Javascript中,这是什么意思底线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var Gallery = Backbone.Controller.extend({
    _index: null,
    _photos: null,
    _album :null,
    _subalbums:null,
    _subphotos:null,
    _data:null,
    _photosview:null,
    _currentsub:null,
    routes: {
        "": "index",
        "subalbum/:id": "subindex",
        "subalbum/:id/" : "directphoto",
        "subalbum/:id/:num" : "hashphoto"
    },
    initialize: function(options) {
        var ws = this;
        if (this._index === null){
            $.ajax({
                url: 'data/album1.json',
                dataType: 'json',
                data: {},
                success: function(data) {
                    ws._data = data;
                    ws._photos =
                    new PhotoCollection(data);
                    ws._index =
                    new IndexView({model: ws._photos});
                    Backbone.history.loadUrl();
                }
            });
            return this;
        }
        return this;
    },
    //Handle rendering the initial view for the
    //application
    index: function() {
        this._index.render();
    },

我读放在这里Backbone.js的教程:<一href=\"http://addyosmani.com/blog/building-spas-jquerys-best-friends/\">http://addyosmani.com/blog/building-spas-jquerys-best-friends/

什么是底线? (_index,_photos,_album)为什么使用它们?

What are the underscores? (_index, _photos, _album) Why use them?

推荐答案

这意味着私人领域或私有方法。方法,这些方法仅用于内部使用。

It means private fields or private methods. Methods that are only for internal use.

他们不应该之类的外部调用。

They should not be invoked outside of the class.

私有字段包含供内部使用的数据。

Private fields contain data for internal use.

它们不应该被读出或从类以外写入(直接地)。

They should not be read or written into (directly) from outside of the class.

这篇关于在Javascript中,这是什么意思底线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆