When you execute /^\d+$/.test('16') , you call the test function with your regular expression as the this object (i.e., as a method call to the object).
When you run t(16) , you have no object specified, and therefore this defaults to the top object, which is window .
To reproduce the first behavior, you will need to do this:
var r = /^\d+$/; var t = r.test; t.call(r, 16);
source share