Search code examples
javascriptcoffeescriptframerjs

JavaScript: Writing convention and the differences


I am confused with the way I write my and I am wondering what are the differences between? They all generate the same result but which is the best way to write it?

I am using Framer.js library for prototyping. I do aware Framer.js uses but I am writing them in vanilla .

Difference 1

framerOnboard.card1.states.animationOptions({
    curve: "spring(200, 20, 0)"
});

framerOnboard.card1.states.animationOptions = {
    curve: "spring(200, 20, 0)"
};

Difference 2

framerOnboard.card1.states["switch"]("two");

framerOnboard.card1.states.switch("two");

Solution

  • Difference 1

    animationOptions.- It is a function that receives as a parameter an object. This object has a key and this key has a string value.

    framerOnboard.card1.states.animationOptions({
        curve: "spring(200, 20, 0)"
    });
    

    animationOptions.- It is an object with a key and this key has a string value.

    framerOnboard.card1.states.animationOptions = {
        curve: "spring(200, 20, 0)"
    };
    

    Difference 2

    There is no difference.

    Check this example:

    var framerOnboard = {};
    framerOnboard.card1 = {};
    framerOnboard.card1.states = {};
    framerOnboard.card1.states.switch = function(arg) // It's a function.
    {
        alert(arg);
    };
    

    You can execute this functions in two ways:

    framerOnboard.card1.states["switch"]("two");
    

    Or

    framerOnboard.card1.states.switch("two");
    

    http://jsfiddle.net/dannyjhonston/un693467/1/