The term anonymous object could be a confusing term so allow me to clarify: by anonymous object I mean the declaration of an object in the same way you would define an anon function.
example:
someFunction=function(){}
someObject={}
but more specifically anonymous in the way that they can be placed anywhere a variable of such an object or function could be placed. Best (and directly relevant) example being Object.create, now like one would use window.setTimeout(function(){},ms) (that own function’s querks aside) whereas you would just place a function in a variable’s stead, I want to be able to do this: object.Create(some__proto__object,{cake:false}) which is all fine and dandy until I attempt to include methods. Then it throws TypeError: descriptor must be object.
So I do some testing in console, I put in {} all good, {cake:"cheesecake",taste:"delicious"} ok,
variable={
cake:"cheesecake",
taste:"celicious",
stateTheCatch:function(){console.log('The cake is a pie!')}
}
it works, but
//In practical use:
//Object.create(inheritanceObject,
{
cake:"cheesecake",
taste:"celicious",
stateTheCatch:function(){console.log('The cake is a pie!')}
}//);
is broken, and not counted as an object. Why is this bad? Because you type it like that in the second argument for Object.create besides using an identifier. So and clues why it doesn’t work like that?
That’s because you are not creating an object at all. When used as a statement, the brackets create a code block, not an object literal.
You can put brackets around any code, but it doesn’t do much. (Variables have function scope, so it doesn’t even scope variables.)
If you use the object as a value, it works:
In Javascript functions are objects, so you can use a function value anywhere you use another value. It can be sent as parameters, and be stored in variables, object properties and arrays.