Skip to content
Advertisement

Tag: object-literal

javascript object literals — formula

I’m supposed to declare an object literal, accepting a parameter that gets the radius of the circle. Then returns the area of the circle. Not sure how to implement the formula A = PIr^2 This is what I have so far. Am I in the right direction? Answer I am not sure why you have the a and b property.

Call functions from function inside an object (object literal)

I’m learning to use object literals in JS, and I’m trying to get a function inside an object to run by calling it through another function in the same object. Why isn’t the function “run” running when calling it from the function “init”? Answer That code is only a declaration. You need to actually call the function: Demo: http://jsfiddle.net/mattball/s6MJ5/

How to Sort a JS Object Literal?

If I have this JS object literal: How can I create a new, sorted object literal: Answer Re: How to sort a JS Object? Answer: You can’t. So instead, you need a more sophisticated data structure. You have many options: You can use a separate array to hold the order of the object’s keys. (This is what @Felix Kling’s answer

JavaScript property access: dot notation vs. brackets?

Other than the obvious fact that the first form could use a variable and not just a string literal, is there any reason to use one over the other, and if so under which cases? In code: Context: I’ve written a code generator which produces these expressions and I’m wondering which is preferable. Answer (Sourced from here.) Square bracket notation

Advertisement