www.webdeveloper.com
Results 1 to 7 of 7

Thread: uniqueInteger.counter throws me Reference error

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    84

    Thumbs down uniqueInteger.counter throws me Reference error

    I'm trying in Firebug a code decripted in theJavascript definitive guide

    PHP Code:
    // Initialize the counter property of the function object.
    // Function declarations are hoisted so we really can
    // do this assignment before the function declaration.
    uniqueInteger.counter 0;
    // This function returns a different integer each time it is called.
    // It uses a property of itself to remember the next value to be returned.
    function uniqueInteger() {
    return 
    uniqueInteger.counter++; // Increment and return counter property

    But when i execute it, firebug throws me reference error at uniqueInteger.counter = 0;

    Why? It's a syntax allowed in some browser and not in other?

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    No the script should work. Did you enter the whole script all at once or row by row in the console? (The latter would give an error.)

  3. #3
    Join Date
    Jan 2013
    Posts
    84
    I've prolem with another code too

    PHP Code:
    function range(fromto) {
      var 
    inherit(range.methods);
      
    r.from from;
      
    r.to to;

      return 
    r;
    }


    includes: function(x) { return this.from <= && <= this.to; },

    foreach: function(
    f) {
    for(var 
    Math.ceil(this.from); <= this.tox++) f(x);
    },

    toString: function() { return "(" this.from "..." this.to ")"; }
    };

    var 
    range(1,3); // Create a range object
    r.includes(2); // => true: 2 is in the range
    r.foreach(console.log); // Prints 1 2 3
    console.log(r); // Prints (1...3) 
    this give me error at the line includes: function(x) { return this.from <= x && x <= this.to; }


  4. #4
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Quote Originally Posted by American horizo View Post
    for all at once do you mean copy/paste all the code in the editor?
    Well I meant writing the code in a HTML document and then showing the document in the browser - I should have explained that clearer. Pasting everything in the Firebug console gives me an error too. (I don't know completely how Firebug's console works, but I don't think writing code in it is the best idea - it's more for debugging code on a webpage.)

    Quote Originally Posted by American horizo View Post
    PHP Code:
    function range(fromto) {
      var 
    inherit(range.methods);
      
    r.from from;
      
    r.to to;

      return 
    r;
    }


    includes: function(x) { return this.from <= && <= this.to; },

    foreach: function(
    f) {
    for(var 
    Math.ceil(this.from); <= this.tox++) f(x);
    },

    toString: function() { return "(" this.from "..." this.to ")"; }
    };

    var 
    range(1,3); // Create a range object
    r.includes(2); // => true: 2 is in the range
    r.foreach(console.log); // Prints 1 2 3
    console.log(r); // Prints (1...3) 
    It seems you have just copy and pasted in random code snippets here. Explain what you're trying to do instead... :/

  5. #5
    Join Date
    Jan 2013
    Posts
    84
    for all at once do you mean copy/paste all the code in the editor?
    Anyway i've tryied both methods and doesn't work

  6. #6
    Join Date
    Jan 2013
    Posts
    84
    I've posted this code because i have problem with it too using firebug... Now i've undertand that firebug isn't good, so from now i will write the code inside html
    Anyway i didn't understand what means "includes: function"... now i've understand it, it's a parameter of the object.. I had not seen that it was preceded by the inizializator range.methods = {

  7. #7
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Ok, good. :) I'll just say that Firebug is a great tool for debugging purposes - it's just not especially good when you're learning and experimenting with the JavaScript language.

Thread Information

Users Browsing this Thread

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

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