返回顶部
首页 > 资讯 > 精选 >Javascript Study Memo
  • 913
分享到

Javascript Study Memo

2023-06-03 01:06:56 913人浏览 薄情痞子
摘要

javascript basic concept.....[@more@]Instance property: property defined in constructor:function Circle(radius) {this.ra

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

--结束END--

本文标题: Javascript Study Memo

本文链接: https://lsjlt.com/news/232068.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作