Do all methods have to be stated after all properties in JavaScript when defining objects in object literal form? I have tried voiding this idea and it seems that all properties stated afterwards are not included.
Asked
Active
Viewed 41 times
-1
-
1Something does not seem right. Show a code example that you base your conclusion on. – PM 77-1 Jun 30 '14 at 02:57
-
Perhaps you messed up your braces, sticking the subsequent properties into the function body. – user2357112 Jun 30 '14 at 03:00
-
Yes, I found my mistake. Thanks to you both – Jabari King Jun 30 '14 at 03:10
1 Answers
0
Do all methods have to be stated after all properties in JavaScript when defining objects in object literal form?
No.
Object properties have a value that is either a primitive or a reference to an object. The order in which they are added, either by a literal or assignment, is irrelevant:
var obj = {
prop0: 0,
method0: function(){},
prop1: 1,
method1: function(){}
}

RobG
- 142,382
- 31
- 172
- 209