Javascript Study Memo
短信预约 -IT技能 免费直播动态提醒
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 propertyreturn 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);
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341