SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Setting object to inherit in IE

    Hi all,

    I've been messing around with Javascript and working in Firefox.
    I did this:

    Code JavaScript:
    A = {
       prop:"prop"
    };
     
    B = {};
     
    B.__proto__ = A;
    alert(B.prop); // works

    However, this doesn't work in IE (not yet tested Safari etc). Does anyone know of a way of doing this or something similar in IE? Thanks a lot if so - it's very useful.

    All the best

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think i've ever had this problem, so I'm not sure if this is fully what you need.

    http://www.crockford.com/javascript/inheritance.html


  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks g, so how do you get an object to inherit from another like this?

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as above, I have had no real need for this so I can only guess. I'd assume using prototype and going

    B = C();
    B.prototype = new A();

    I haven't used prototype yet as I create all my own classes in different ways, but I assume B.prototype = new A(); would allow you to access A's properties via B.property.

    HTH


  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again Gav - I managed to completely miss the link in your first comment and am reading it now- that's what happens when you rush!

    Kindest regards


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
  •