SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question function () clarification

    hi,
    i want to know that what is function()={function details etc. }

    e.g. element.onmouseover=function(){this.className='myclass';return false}

    what is the meaning of above.
    Some times when i put just element.onmouseover = function onclicking() does not work but above method works.

    Pls clarify me about this

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by viveknarula View Post
    e.g. element.onmouseover=function(){this.className='myclass';return false}
    The above will trigger the anonymous function once the onmouseover is triggered. You could name the function as well:
    Code:
    element.onmouseover= doSomething;
    
    function doSomething() {
        this.className='myclass';return false
    }
    Note that the above assignment does not include the (), that would trigger the function right away.

  3. #3
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Thanks Pepejeria for your reply.
    What about the other method of function. Sometimes second method does not works but First one works.

    Thanks

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your second example you provided is not correct. Can you please clarify it?

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    I'm going to see if i can get the right name for this Literal Notation...I could be wrong but i can't recall the exact name for this but basically:
    Code:
    var someVar = function() {
        ...
    };
    
    someVar();
    is the same thing as:
    Code:
    function someFunc() {
        ...
    }
    
    someFunc();
    Except you see the first one in more objected oriented like designs or something like that...its late for me so my brain isn't at .5% tonight as it usually is.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I wouldn't call it object oriented.

  7. #7
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by Pepejeria View Post
    Your second example you provided is not correct. Can you please clarify it?

    I may be wrong in providing second example. what i mean is like
    <input type=text onclick= function test()>

    where test is


    function test ()
    {
    function details etc
    }

  8. #8
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correct syntax for that would be following:
    Code:
    <input type="text" onclick="test();"> 
    
    
    function test() {
        // 
    }


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
  •