Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript "Counter" object, what is it?

I just noticed by accident that WebKit and Firefox define a global variable called "Counter" in the window. Any idea of what this is?

On Chrome, it appears as such in the watch:

Counter: function Counter() { [native code] }

Note: this variable is not present on IE (tested with version 10)

like image 368
Gyum Fox Avatar asked Mar 13 '13 11:03

Gyum Fox


2 Answers

http://blog.peschla.net/doxygen/v8_chromium_r157275/v8-counters_8h.html

I believe this is saying counters is for garbage collection, counting the number of references to any given data. Direct or Indirect to help it create a more accurate pointer for recalling that data or releasing it from cache? correct me if i am wrong, I am new..It was just more fun to google than to study.

like image 59
Four_lo Avatar answered Oct 31 '22 13:10

Four_lo


The best I could find is related with Rhino: https://developer.mozilla.org/en-US/docs/Rhino/Embedding_tutorial#Counter_example

But in webkit it fails to instanctiate:

var c = new Counter(7)
TypeError: Illegal constructor

var c = Counter(7)
TypeError: Illegal constructor

In Gecko:

[12:33:24.608] var c = Counter(7)
[12:33:24.609] TypeError: Counter is not a function
[12:33:29.049] var c = new Counter(7)
[12:33:29.051] TypeError: Counter is not a constructor
[12:33:31.043] Counter
[12:33:31.046] [object Counter]
like image 36
fmsf Avatar answered Oct 31 '22 13:10

fmsf