What does this method is called in JavaScript

Discussion in 'JavaScript' started by ketting00, Feb 25, 2014.

  1. #1
    Sorry for very stupid question, I'm not an English speaker and it's very hard for me to find keyword in search for deeper knowledge of something like this:

    
    var foo = {
       bar: function( i ) {
         this.i = i;
         console.log( 'It\n's ' + i );
       }
    }
    var x = 'fubar';
    var y = foo.bar( x );
    
    Code (markup):

     
    ketting00, Feb 25, 2014 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    I think your question was "What does this method do in JavaScript?"

    Answer is:
    [​IMG]
    It creates an object called foo and then creates a method inside that object called bar which can take one parameter called i. It then logs into the console "It's i" (i being what's being passed) which is set to x and then called with y = foo.bar(x).
     
    HuggyStudios, Feb 25, 2014 IP
  3. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #3
    Thanks,

    That was what I need to know.
    It's called storing function in object then.
     
    ketting00, Feb 25, 2014 IP
  4. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165