GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Thursday, December 16, 2010

Advance Javascript - Anonymous Function

Anonymous function is a block of code that directly executed like there's no function.

>> (function(){
>>    var doc = document.getElementById('satu');
>>    doc.innerHTML = "Luna Maya";
>> })();

If you declare a function in inner the anonymous function, you should call it in the inner also.

>> (function(){
>>    function lol(){
>>        var doc = document.getElementById('satu');
>>        doc.innerHTML = "Luna Maya";
>>    }
>>    lol();
>> })();

Here's a simple code:
<script>
    function show(msg){
        alert(msg);
    }
    show((function(){
              return 'hello, lady gaga';
          })());
</script>
               

Share/Bookmark

No comments:

Post a Comment