Javascript Functions and Objects
<p>I am learning Javascript, I have been using PHP for about 10 years so I have some knowledge of Javascript, mostly just using jQuery and hacking it together, I think it's time I put some effort into learning it better so I have been reading up on it.</p>

<p>Below are my examples of defining and calling some functions.</p>

<p><strong>Method 1</strong></p>

<pre><code>function testFunction1() {
    console.log('TestFunction1() was ran');
}
testFunction1();
</code></pre>

<hr>

<p><strong>Method 2</strong> </p>

<pre><code>var testFunction2 = function() {
    console.log('TestFunction2() was ran');
}
testFunction2();
</code></pre>

<hr>

<p><strong>Method 3</strong></p>

<pre><code>var TestFunction3 = {
    flag: function() {
        console.log('TestFunction3.flag() was ran');
    },
    unflag: function() {
        console.log('TestFunction3.unflag() was ran');
    }
};
TestFunction3.flag();
TestFunction3.unflag();
</code></pre>

<hr>

<p><strong>Method 4</strong></p>

<pre><code>var TestFunction4 = {
    Like: {
        comment: function() {
            console.log('TestFunction4.Like.comment() was ran');
        },
        user: function() {
            console.log('TestFunction4.Like.user() was ran');
        }
    },
    Unlike: {
        comment: function() {
            console.log('TestFunction4.Unlike.comment() was ran');
        },
        user: function() {
            console.log('TestFunction4.Unlike.user() was ran');
        }
    }
};
TestFunction4.Like.comment();
TestFunction4.Like.user();
TestFunction4.Unlike.comment();
TestFunction4.Unlike.user();
</code></pre>

<hr>

<p>Ok so I understand method 1 and 2 to be just a basic function call.</p>

<p>1)<br>
Method 3 and 4 are where my questions start, from other post and from reading, I cannot tell if these are still considered a basic function with namespacing applied, or if these would be considered Objects?</p>

<p>2)<br>
I have seen where sometimes an object would be called with the <code>new</code> word however running all this in the browser works fine so I am guessing this is not an object?  If it is not an object, how would I make it into an object?</p>

<p>3)<br>
Example 3 and 4 are pretty much the same with the exception that example 4 has functions defined 1 level deeper then example 3, is there a name for example 3 and 4 or are they considered the same thing?</p>

<p>4)<br>
Lastly of all the 4 examples, is any of these 4 methods preferred over the other?</p>

<p>Sorry for all the questions in 1 but they are all related and I don't think I need to start 4 separate questions for this.</p>
