Reputation: 148644
var t={a:"1",b:"2"}
is this an Object
with properties (a,b)
or it is
a Javascript Labeled Statement
?
Or does it depends on the context ?
what about this ?
I was wondering for why Eval wrap itself with ( )
It is there to resolve confusion. (statement vs expression)
Fine.
But
{"a":"1"}
can't ever be Labeled statement
( because of the "
which wraps the a
) , it is illigle and invalid !!!
so it Only be a Object with properties !!!
just as much as {a:"1"} can only be a Labeled statement and not an object with properties (properties should come with { " a ":"1"}
So why Eval cant check it ?
Upvotes: 0
Views: 88
Reputation: 6136
These are objects defined using javascript literal notation.
Upvotes: 0
Reputation: 1039210
var t={a:"1",b:"2"}
is an object with properties a
and b
.
what about this ?
$.ajax({
type: 'POST',
url: '../Handler...',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: $.toJSON(jsonObj),
cache: false,
...
});
This is a call to a function called $.ajax()
and passing an object with properties type
, url
, dataType
, contentType
, data
, cache
, ... as parameter.
why Eval cant check it ?
Pardon me?
Upvotes: 3
Reputation: 62603
It is JSON (JavaScript Object Notation) data. In your case, the data is being assigned to a variable.
Fundamentally, JSON is a set of key-value pairs. Take a look at the JavaScript example for more clues.
Upvotes: 2