Javascript / jquery error "invalid object initializer"

I call the function as follows:

myfunc($tab, {'top-left', 'bottom-left'}, defaults.tabRounded);

Function Definition:

function myfunc(obj, properties, value) {

But I get the error "Invalid object initializer". Is this because of the json argument? Or something else?

+5
source share
4 answers

Replace

myfunc($tab, {'top-left', 'bottom-left'}, defaults.tabRounded);

WITH

myfunc($tab, ['top-left', 'bottom-left'], defaults.tabRounded);

{'top-left', 'bottom-left'}not an object, but {'top-left': 0, 'bottom-left': 10}an object. I suggested that you might need an array instead of an object.

+6
source

JavaScript objects are key / value pairs:

{
    'top-left': 333,
    'bottom-left': 444
}

https://developer.mozilla.org/en/JavaScript/Guide/Working_with_Objects#Using_Object_Initializers

+2
source

, , :

myfunc($tab, ['top-left', 'bottom-left'], defaults.tabRounded);

, , . - :

myfunc($tab, {'top-left': 100, 'bottom-left': 100}, defaults.tabRounded);
0

You need to name properties like {x: 'foo', y: 'bar'}, since they are always key-value pairs.

0
source

All Articles