Javascript Function

Functions are link to Function.prototype. Function.prototype is linked to Object.prototype.

Since functions are object, they can have property, method, they can be passed to functions.

The missing parameter will have value  undefined

A function always returns a value. If the return value is not specified, then undefined is returned.

every function receives two additional parameters: this and arguments.

Invocation 





pattern of invocation:

the method invocation pattern - When a function is stored as a property of an object, we call it a method, this is bounded to the object

the function invocation pattern - When a function is NOT the property of an object. this is bounded to global object, ( window in DOM ). THIS IS A DESIGN MISTAKE, this should be bounded to ccurrent context instead

the constructor invocation pattern - this binds to newly created object

and the apply invocation pattern





Inner Functions

REMEMBER: inner function has no access to this and arguments
inner functions are created and disposed every time a function is called. In the example below, bar should be moved outside of foo. The same applies to anonymous function. 

function foo(a, b) {  
    function bar() {  
        return a + b;  
    }  
  
    return bar();  
}  
  
foo(1, 2);  

document.addEventListener("click", function(evt) {  
    alert("You clicked the page.");  
}); 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值