title: In JavaScript: Syntax difference between function & method definition within a class
body: <p>The Object class has both methods and functions meaning they both are accessed through Object.nameOfMethodOrFunction(). The following question <a href="https://stackoverflow.com/questions/155609/what-is-the-difference-between-a-method-and-a-function">What is the difference between a method and a function</a> explains the difference between a method and and a function, but it doesn't explain how to create them within an object.  For example, the code below defines the method sayHi.  But how do you define a function inside the same object?</p>
  
  <pre><code>var johnDoe =
  {
        fName : 'John',
        lName: 'Doe',
        sayHi: function()
        {
          return 'Hi There';
        }
  };
  </code></pre>