Results 1 to 2 of 2

This is a discussion on Javascript OO - can't define a class properly within the Plugins Development section, part of the Chrome Plugins category: Hi all. I'm probably doing something stupid but I can't get started with OO in Javascript. (It's been a while.) ...


  1. #1
    Fatman_UK is offline Junior Member
    Join Date
    Nov 2010
    Posts
    1

    Unhappy Javascript OO - can't define a class properly

    Hi all.

    I'm probably doing something stupid but I can't get started with OO in Javascript. (It's been a while.) Nothing is working properly. My latest mistake is:

    Code:
    var Blob = Class.create({
       initialize: function(text) {
          this.text = text;
          this.count = 0;
       }
    });
    I get "Uncaught ReferenceError: 'Class' is not defined" in the Extensions debugger, just under the "var Blob" line. Do I need to include something?

    Before that I tried:

    Code:
    function Blob(text) {
       this.text = text;
       this.count = 0;
    }
    
    Blob.prototype = { }
    which seemed to work, until I noticed that member "this" pointed at the DomWindow. Not what I need at all.

    Can someone give me a working example of a class, since I appear to be too thick to work it out myself?

    I'm running chromium-browser 8.0.561.0 (63476) Ubuntu 10.04, if that sheds any light on my problem.

    Thanks.

  2. #2
    devnull69 is offline Member
    Join Date
    Jul 2010
    Posts
    32

    Default

    close ... but a miss ;-)

    Code:
    function Foo()
    {
        this.x = 1;
        this.y = 2;
    }
     
    obj = new Foo;
    console.log(obj.x);
    You can use .prototype to define additional properties and even some kind of inheritance/hierarchy of objects.

Similar Threads

  1. Web pages randomly don't load properly.
    By wanabeswordsman in forum Chrome Troubleshooting
    Replies: 5
    Last Post: 12-02-2010, 05:16 PM
  2. Some pages refuse to display properly?
    By SifJar in forum Chrome Troubleshooting
    Replies: 1
    Last Post: 10-19-2010, 03:18 AM
  3. theme request the Enterprise NX01 class
    By Winter in forum Chrome Themes
    Replies: 11
    Last Post: 09-09-2010, 09:44 PM
  4. chrome failled to initialize properly
    By Robertofor in forum Chrome Troubleshooting
    Replies: 0
    Last Post: 08-10-2010, 04:37 AM
  5. Chromeplugins webpage not displaying properly
    By kausikdatta in forum Bugs and Vulnerabilities
    Replies: 4
    Last Post: 09-14-2008, 01:54 AM

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
  •