相关疑难解决方法(0)

JavaScript中属性和方法名称的下划线前缀

JavaScript中的下划线前缀只是一个约定,例如在Python私有类方法中是什么?

从2.7 Python文档:

Python中不存在除了从对象内部访问之外无法访问的"私有"实例变量.但是,大多数Python代码都遵循一个约定:前缀为下划线的名称(例如_spam)应被视为API的非公共部分(无论是函数,方法还是数据成员) .

这也适用于JavaScript吗?

以此JavaScript代码为例:

function AltTabPopup() {
    this._init();
}

AltTabPopup.prototype = {
    _init : function() {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

此外,使用下划线前缀变量.

    ...
    this._currentApp = 0;
    this._currentWindow = -1;
    this._thumbnailTimeoutId = 0;
    this._motionTimeoutId = 0;
    ...
Run Code Online (Sandbox Code Playgroud)

只有会议?或者下划线前缀后面还有更多?


我承认我的问题与这个问题非常相似,但它并没有让人更聪明地了解JavaScript中下划线前缀的重要性.

javascript scope naming-conventions

216
推荐指数
6
解决办法
16万
查看次数

JavaScript原型'这个'问题

这是我上一期提问的后续问题.

简单的javascript原型问题

我是一个使用JavaScript的新人prototype,很抱歉第二篇文章.

我想点击的元素分配id给this.name数组.

task.prototype.init=function(){  
      this.name=[];  //this.name array has to be defined here

        for (var i; i<5; i++){
            var Link=document.createElement('a');
                Link.innerHTML='click';
                Link.id=value[i];   //I want to assign the value to the this.name array
                Link.href='#'
                Link.onclick=this.changeName;
                document.body.appendChild(Link);
         }
}
task.prototype.changeName=function(){  

     //How do I push the this.id to the property this.name?

     //the code below won't work because this refer to the <a> element. 
     this.name.push(this.id);     

    return false;
    }
Run Code Online (Sandbox Code Playgroud)

有关任务的任何提示吗?

javascript

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×2

naming-conventions ×1

scope ×1