SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Studying this code: in need of explanation

    Hello,

    Today, I'm studying Lea Verou's prefixfree: https://raw.github.com/LeaVerou/pref.../prefixfree.js

    I have a question about this approach:

    Code JavaScript:
     
    (function(){
     
     
    var self = window.StyleFix = {
    	link: function(link) {
    		try {
    			...
    		}
    		catch(e) {
    			return;
    		}
     
    ...

    Wht is the reason to use var self = ... ?


  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rhgiant View Post
    What is the reason to use var self = ... ?
    Seemingly to get a reference to the the object being generated, without having to use closures or other techniques.
    self is an ill-advised name choice because it overwrites window.self, which other scripts may try to use.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply
    Why would one avoid closures?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •