In both examples you're defining the variable Array to be a function that assigns this to secrets. It just so happens that there already exists a global object called Array that other JS in the page might or might not use as a Constructor to make arrays. If you pop into your console and re-assign Array to be something else, you might start getting errors from code that explicitly depends on Array. However, arrays made literally with [] continue to work just fine, and in fact, their __proto__ still points to what was Array.prototype. So:
var arr1 = new Array('a','b','c');
// arr[0] -> 'a'
var arr2 = ['d','e','f'];
// arr[0] -> 'd'
var secrets;
Array = function() { secrets = this; };
var arr3 = new Array('g','h','i'); // nothing wrong here, because Array is a function
// arr3[0] -> undefined
// Array is just a function, you can't make arrays with new Array anymore
// and arr3 is just a function
var arr4 = ['j','k','l'];
// arr4[0] -> 'j'
// making array literals still works
as for this, nothing strange, still follows the rules of this. the fact that you're assigning a function to Array doesn't change how this behaves. so this points to the global object which in the browser is window unless you instantiate with new or use call or apply
the difference between both samples is the difference between a function expression and function declaration, see: What is the difference between a function expression vs declaration in Javascript?
thisworks is explained in the MDN documentation (in short: the value depends on how the function is called) and whetherArray = function()...orfunction Array()...are the same is answered in this question.thisI have read the documentation but was not able to figure out whatthisrefers to in the above context... Can you or someonelse please help?? Regarding the second part of my question, I read the post you provided and I better understand now.Arraywithnew, then it will refer to an empty object inheriting fromArray.prototype. If it is called withoutnew, it will refer towindow. If it is called via.callor.apply, it will refer to the element which is passed as first argument. In order to know how it is called, you have to have a look atJSON.parse.Arrayis not called byJSON.parse