温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Javascript Study Memo

发布时间:2020-08-06 22:44:16 来源:ITPUB博客 阅读:129 作者:gehuiwin 栏目:编程语言

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);

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI