Results 1 to 4 of 4

Thread: Trying to understand code.

  1. #1
    Join Date
    Jun 2014

    Trying to understand code.

    I'm a newbie n trying to understand a code but got stuck in a portion, not sure why it is written like this in code . Is there any other way to write this . Please help me understand it.

    Var entry ={
    'Wise' : true, //don't go offscreen ,don't overlap
    'Margin':10, // minimum allowed distance
    'Gap' :0,
    'Align' : 'tcbc'


  2. #2
    Join Date
    Mar 2007
    var entry = {}; or it could be var entry = new Object(); the {} is short hand for Object()

    var entry = {};
    entry.Wise = true;
    entry.Margin = 10;
    entry.Gap = 0;
    entry.Align = "tcbc";

    You could also use the with clause,

    Wise = true;
    Margin = 10;
    Gap = 0;
    Align = "tcbc";

    but that is now frowned upon and not valid when you are using the strict method of JavaScript which is something relativity new and IMHO a pain in the rear because some stuffed shirt in ECMAScript standardization organisation is trying to justify their job position.

    As you can see, the method you already have is the shortest method of creating an object with properties that have values.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Dec 2011
    Centurion, South Africa
    Please make sure your keyword casing is correct (eg. var), JavaScript is very strict about that too. Semi-colon at the end of your assignments please ( ; )
    Object member keys do not need to be quoted usually, so this is also correct and will conform to strict mode as well:

    var entry = {
    	Wise   : true, //don't go offscreen ,don't overlap
    	Margin : 10,   //minimum allowed distance
    	Gap    : 0,
    	Align  : 'tcbc'

  4. #4
    Join Date
    Dec 2005
    Nice explanations.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles