Javascript Study Memo

Javascript basic concept.....

[@more@]
  • Instance property: property defined in constructor:
    function Circle(radius) {
    	this.radius = radius;	
    }
    
  • Class property: property belongs to class. all instances share the only copy of class property:
    Circle.PI = 3.141592;
    Circle.UNIT = new Circle(1);
    	
    	
  • Instance method:An instance method can be invoked for any instance of a class, but this does not mean that each object contains its own private copy of the method, as it does with instance properties.Instead, instance method is defined by prototype property:
    Circle.prototype.area() { // notes: must explicitly specify thiskeyword to property
    	return Circle.PI * this.radius * this.radius;
    }
    	
  • Class method: method associated with a class rather than an instance of a class:
    Circle.max = function (a,b) {
    	if (a.r > b.r) {
    		return a;
    	}else {
    		return b;
    	}
    }
    

Function execute & Call Object Concept

When Invoke a function, the function scope is set to scope chain, and then add a new object known as call object to the front of the scope chain. the call object is initialized with parameters, local variable. If a nested function is invoked, the scope chain includes three objects: its own call object, the call object of outer object , and the global object.
uniqueID = function(){ // user can set id back to 0 by: uniqueID.id = 0
    if (!arguments.callee.id) 
        arguments.callee.id = 0;
    return arguments.callee.id++;
};

uid = (function(){ // closure, id is persistent and private
    var id = 0;
    return function(){
        return id++;
    };
})();

var ret = "";
var i = 10;

while (i--) {
    ret += uniqueID() + "t";
    uniqueID.id = 0;
}
alert(ret);

i = 10;
ret = "";
while (i--) {
    ret += uid() + "t";
}
alert(ret);

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7845854/viewspace-1024489/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7845854/viewspace-1024489/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值