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?
var r = 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; }
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.)
Originally Posted by American horizo
PHP Code:
function range(from, to) { var r = inherit(range.methods); r.from = from; r.to = to;
return r; }
includes: function(x) { return this.from <= x && x <= this.to; },
foreach: function(f) { for(var x = Math.ceil(this.from); x <= this.to; x++) f(x); },
var r = 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... :/
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 = {
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.
Bookmarks