SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Configuration Object

    Hi,
    what's the way to avoid configuration
    object is undefined ?
    Code JavaScript:
    var MYAPP = {};
    MYAPP.dom = {};
    MYAPP.dom.Button = function(text, conf) {
      var type = conf.type || 'submit';
      var font = conf.font || 'Verdana';
    }
    /*
    Error: conf is undefined
    */
    MYAPP.dom.Button('mytest');
    /*
    It works
    */
    MYAPP.dom.Button('mytest',{});

    I'm thinking about a way like
    Code JavaScript:
    var MYAPP = {};
    MYAPP.dom = {};
    MYAPP.dom.Button = function(text, conf) {
      conf = conf || {};
      var type = conf.type || 'submit';
      var font = conf.font || 'Verdana';
    }
    /*
    It works
    */
    MYAPP.dom.Button('mytest');

    Is it the right way ?
    Bye.

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by whisher View Post

    I'm thinking about a way like
    Code JavaScript:
    var MYAPP = {};
    MYAPP.dom = {};
    MYAPP.dom.Button = function(text, conf) {
      conf = conf || {};
      var type = conf.type || 'submit';
      var font = conf.font || 'Verdana';
    }
    /*
    It works
    */
    MYAPP.dom.Button('mytest');

    Is it the right way ?
    Technically correct but some syntax checkers will give warnings about altering parameter values, so better to assign to a different variable.
    Tab-indentation is a crime against humanity.


Bookmarks

Posting Permissions

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