I'm making a LinkedList class:
function LinkedList(){
...
What is the difference between:
this.addNode = function(data){
...
and
addNode: function(data){
...
I'm making a LinkedList class:
function LinkedList(){
...
What is the difference between:
this.addNode = function(data){
...
and
addNode: function(data){
...
This creates a property on an object (assuming this
references an object)
this.addNode = function(data) { ...
That's an assignment expression, and if it's all by itself then it comprises a statement.
This, on the other hand, is part of an object literal expression:
addNode: function(data) { ...
It only makes sense inside an object literal, which looks like:
var someObject = {
property1: value1,
property2: value2,
// ...
};
In a larger sense, it doesn't make a lot of sense to compare the two; they're two different ways of doing the same thing, in a way, but they make sense in disjoint contexts. The first is a way of adding or resetting a property on an existing object, while the second is a way of setting a property as part of the creation of a new object.