JavaScript - Create New Object (Function) Using an object literal? -


I have defined a function with two javascript: size and url :

  function IconInfo () {this.size = size; This.url = url; }   

Inside another function I am making a new example of IconInfo and set the property in this way:

 < Code> function SomeFunction () {Var icon = New IconInfo (); Icon.size = 64; Icon.url = "http://somesite.com/image1.png"; }   

There is no way to create an event like the following example:

  var icon = new iconInfo ({Size: 64, url: "Http : //somesite.com/image1.png "});   

I think this signaling looks better, it sounds more concise and easy to read.

=========================== Updates ======== ========================

Based on Tim's reply it is done in the following manner: < Pre> var icon = {size: 64, url: "http://somesite.com/image1.png"};

I have the following questions.

Let me assume that I have 2 works both with exact properties and Constructor logic:

  Func1 (x) {this.x = x; } Func2 (x) {this.x = x; }   

And I have a container that keeps some kind of:

  function container () {this.f = null; }   

If I add a single function using that method then how will it actually be?

  ... var container = new container (); Container.x = New F {// F.Funka 1 or Funk 2? X: 10; }    

There are a lot of options, but keeping it simple .. you just do this :

  var icon = {size: 64, url: "http://somesite.com/image1.png"};   

You do not need to declare "type", but you can do this:

  function IconInfo (size, url) This.size = Shape; This.url = url; ); Var icon = New icon Infos (2, "www.google.com");    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -