0

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");
Vennsoh
  • 4,853
  • 5
  • 26
  • 41

2 Answers2

1

Difference 1:

The first one you are invoking the method animationOptions and using {curve: "spring(200, 20, 0)"} as the argument. The second one you are setting framerOnboard.card1.states.animationOptions to be an object with a key as 'curve' and the value as "spring(200, 20, 0)".

Difference 2:

They both do the same thing, which is to invoke the method switch with "two" as the argument. However. the first one is called bracket notation and the second one is called dot notation. Here are some use cases for one over the other.

Stephan Genyk
  • 177
  • 1
  • 6
1

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/