The first fragment takes an object this, regardless of what it is, and assigns a function to its slot (field) with a name method1. thiscan represent different objects, depending on how it is called test1:
- when called as an autonomous function -
test1()- thiswillwindow - when called as a constructor -
new test1()- thisrefers to the object being created - when called through
callor apply- test1.apply(someObject)- thisrefers to the argument
The second fragment takes an object test2and assigns a function to a slot with a name method1.