JavaScript object literal length === undefined?
This is supported in node.js and newer environments. var obj = {a: “a”, b: “b”}; Object.keys(obj).length // 2
This is supported in node.js and newer environments. var obj = {a: “a”, b: “b”}; Object.keys(obj).length // 2
Functions can have properties, that’s what the object literal syntax is for: it allows to define a call signature and additional properties. Your two examples are equivalent because the second doesn’t define additional properties on the object literal. You can read more on that in the section on hybrid types. Additionally, the object literal allows …
That code is only a declaration. You need to actually call the function: RunApp.init(); Demo: http://jsfiddle.net/mattball/s6MJ5/
Because “key” + test is an expression and not an identifier nor a string literal nor a number literal, which are the only things that are allowed as the key in an object literal. You have to use the [] notation after creating the object for such a dynamic key: var test123 = {}; test123[“key” …
Why not just use a dictionary? p = {‘name’: ‘John Smith’, ‘age’: 23} print p print p[‘name’] print p[‘age’]
The prototype object is meant to be used on constructor functions, basically functions that will be called using the new operator to create new object instances. Functions in JavaScript are first-class objects, which means you can add members to them and treat them just like ordinary objects: var STORE = { item : function() { …
In ES2015 a.k.a ES6 version of JavaScript, a new datatype called Map is introduced. let map = new Map([[“key1”, “value1”], [“key2”, “value2”]]); map.get(“key1”); // => value1 check this reference for more info.
You are missing some code there, but I assume its part of an object declaration like this: var obj = { queryString: function() { //some code } }; obj.queryString(); It assigns a function as a property of an object literal. It would be equivalent to this: var obj = {}; obj.queryString = function() { … …
As BoltClock mentioned there is no object literal in PHP however you can do this by simply type casting the arrays to objects: $testArray = array( (object)array(“name” => “John”, “hobby” => “hiking”), (object)array(“name” => “Jane”, “hobby” => “dancing”) ); echo “Person 1 Name: “.$testArray[0]->name; echo “Person 2 Hobby: “.$testArray[1]->hobby;
That’s not JSON. It’s just Javascript objects, and has nothing at all to do with JSON. You can use brackets to set the properties dynamically. Example: var obj = {}; obj[‘name’] = value; obj[‘anotherName’] = anotherValue; This gives exactly the same as creating the object with an object literal like this: var obj = { …