0

What is difference betwen using this.add and this._add in Famo.us framework. I am little confused with that _add part (naimin conventions that underscore in front of variable or method name 'mimics' private variable or method), but in code ther is no _add method.

Example:

 function _createStripViews(){

    this.stripViews = [];
    this.stripModifiers = [];

    var stripData = [
        {title: 'APPAREL', iconUrl: './img/apparel_icon.png', stripColor: '#00aaac', textTitle: './img/apparel_text.png'},
        {title: 'FOOTWEAR', iconUrl: './img/footwear_icon.png', stripColor: '#006a6d', textTitle: './img/footwear_text.png'},
        {title: 'ALL MATERIALS', iconUrl: './img/allMaterials_icon.png', stripColor: '#be326a', textTitle: './img/allMaterials_text.png'},
        {title: 'CHEMISTRY', iconUrl: './img/chemistry_icon.png', stripColor: '#32900e', textTitle: './img/chemistry_text.png'},
        {title: 'ENERGY/GREENHOUSE GAS', iconUrl: './img/energyGreenhouse_icon.png', stripColor: '#cc4300', textTitle: './img/energyGreenhouse_text.png'},
        {title: 'WATER/LAND', iconUrl: './img/waterLand_icon.png', stripColor: '#1a81b6', textTitle: './img/waterLand_text.png'},
        {title: 'PHYSICAL WASTE', iconUrl: './img/physicalWaste_icon.png', stripColor: '#ccb200', textTitle: './img/physicalWaste_text.png'},
        {title: 'RECYCLED', iconUrl: './img/recycled_icon.png', stripColor: '#7d0ea2', textTitle: './img/recycled_text.png'},
        {title: 'ORGANIC', iconUrl: './img/organic_icon.png', stripColor: '#6c00c7', textTitle: './img/organic_text.png'}
    ];

    for(var i = 0; i < stripData.length; i++){

        var stripView = new StripView({
            width: this.options.stripWidth,
            height: this.options.stripHeight,
            title: stripData[i].title,
            color: stripData[i].stripColor,
            iconUrl: stripData[i].iconUrl,
            textTitle: stripData[i].textTitle,
            index: i
        });

        this.stripViews.push(stripView);

        var yOffset = this.options.topOffset + this.options.stripOffset * i;

        var stripModifier = new Modifier({
            transform: Transform.translate(0, yOffset, 0)
        });

        this.stripModifiers.push(stripModifier);
        this._add(stripModifier).add(stripView);

        stripView.pipe(this);
        stripView.on('tap', this.animateStrips.bind(this));

    };
};
Sysrq147
  • 1,359
  • 4
  • 27
  • 49

2 Answers2

1

Actually there is no difference. If you look at the file View.js in the Famo.us framework you will see the following..

/**
 * Alias for add
 * @method _add
 */
View.prototype._add = View.prototype.add;

They are the exact same thing. My guess is that if you want to add an 'add' function to a custom view, you may still reference Views 'add' function using _add.

Hope this helps!

johntraver
  • 3,612
  • 18
  • 17
1

Using the _-prefix is a common pattern in JavaScript when programming in an object oriented manner. It usually means that a instance method/variable is intended as private or protected as JavaScript doesn't really let you do that in a nice way.

Hence, even if you can use both and they currently do exactly the same, I'd advice to use the .add as it's probably the one that is supposed to be publicly exposed.

Alex
  • 1,689
  • 18
  • 27