SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The Global Object

    Dear all,
    Am I correct in assuming that all objects in JavaScript inherit from the global Object (the one that is initialised when the script engine runs).

    I think this is true since object() is a property of the global object. When you use the new operator to create a new object; it first creates an object with no properties and then initializes it using the constructor. I therefore believe that the empty object gets its definition from the global object and therefore inherits from it.

    I believe the window object inherits from the core JavaScript global object. Can the same principle be applied to all newly created objects?

    Many thanks for your opinions.

    Regards,
    YMas

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Yes, that's true.

    For example, if you have

    Code javascript:
    var obj = {foo: 'bar'};
    alert(obj.constructor);

    you will be shown that it belongs to Object()
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •