SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Binding window objects

    I have this script http://pastebin.com/PY922MyL
    How can i bind the slideSwitch method to window such that i can call it with window.slideSwitch() ?

  2. #2
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Not sure if I understand, but have you tried:

    window.onload = functionname
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  3. #3
    SitePoint Addict
    Join Date
    Jul 2009
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by USPaperchaser View Post
    Not sure if I understand, but have you tried:

    window.onload = functionname
    i'm not trying to run it onload.

    i'm trying to create the method in the window object.
    so i should be able to run the method by just typing slideSwitch() in the console.
    but i wan it enclosed in the self executing function and only expose the method to the window object at the end.

    edit: hmm...i'd found the anwser. http://pastebin.com/3CMsCkSK

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by resting View Post
    hmm...i'd found the anwser. http://pastebin.com/3CMsCkSK
    With your code here:

    Code javascript:
    (function($, w) {
        w.slideSwitch = ...
    })(jQuery,window);

    What benefit does that provide over and above the following standard jQuery pattern?

    Code javascript:
    jQuery(function ($) {
        window.slideSwitch = ...
    });
    Last edited by paul_wilkins; Apr 13, 2012 at 02:08.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •