'This' in the phone stumble

What is 'this' in a telephone bundle? I am working on an application where I have local javascript packed with the application and remote javascript pulled from the server. I use coffeescript to generate all javascript.

Both files are included in the application index header generated via haml as such:

%script{:src=>"javascripts/file1.js"}
%script{:src=>"http://192.168.5.205:3000/assets/file2.js"}

file1.js.coffee:

@myObj1 = property: true

file2.js.coffee:

@myObj2 = property: true

myObj1available all over the world and may be referred to as simple myObj1, but myObj2accessible only through document.myObj2and cannot be called simply myObj2. What's happening?

+3
source share
1 answer

Well, if you say this:

@myObj2 = property: true

myObj2 document.myObj2 , this document, file2.js.coffee. , $(document).ready() (: http://jsfiddle.net/ambiguous/6DFK9/).

, - , window:

# in file1.js.coffee:
window.myObj1 = property: true

# in file2.js.coffee:
window.myObj2 = property: true

, , , , , this , . , : , , window.

+6

All Articles