web前端之JavaScript部分开发规范和细节

来源:互联网 发布:高等教育国家数据平台 编辑:程序博客网 时间:2024/05/15 18:43

web前端之开发规范和细节

1.文件命名方式:App(应用)XxxXxxXxx,以驼峰形式命名

2.方法命名方式: xxxXxxXxx,首字母小写,其余后面驼峰

3.参数命名方式也与上面一样

4./这是一个删除操作 /

每一个方法上面需要书写备注反映其对应的功能或者作用

5.如方法传入哪些参数,并对这些参数进行相应的说明

    6.
,getKey: function(args) {}方法的样式
    7.
a : null,b : null,c :"123"

参数命名方式
为什么不写成以下这样?

a : null,b : null,c :"123"

添加相应数据之后方便其进行添加对应的”,”,如果放在最后容易遗忘造成代码错误

8.”function bind (){}” 和 “bind : function(){}”效果一样,为什么要使用bind : function(){}

var data{    a : null    ,b : null    ,c :"123"    ,bind : function(){    }}

如果是function bind(){},就会报错,要数据重新修改之后才能加入,这无疑会增加工作量。

9.draw: function(type, style){} 对draw的调用:draw (type, style);还是同function draw (type, style){}调用一样

10.

var args = {  url: "foo",  load: this.dataLoaded};dojo.xhrGet(args);报错var args = {  url: "foo",  load: dojo.hitch(this, "dataLoaded")};dojo.xhrGet(args);正确
<script>function Animal(){    this.name  = 'Animal';    this.sleep = function(who){        alert(who + "sleep!!");    }}function Dog(){    Animal.call(this);}function test(){    var dog = new Dog();    dog.sleep("dog");}</script>

call()函数用于调用当前函数functionObject,并可同时使用指定对象thisObj作为本次执行时functionObject函数内部的this指针引用。

<script>function Animal(){    this.name  = 'Animal';    this.eat = function(){        alert(this.name + "  eat!!!");    }}function Dog(){    this.name = 'Dog';        }function test(){    var animal = new Animal();    var dog = new Dog();    animal.eat();    animal.eat.call(dog);}</script>

结果是Animal eat!!!! 和dog eat!!! 这就是常规的用法了。让方法执行在dog的作用域上。this.name就变成了dog。

部分资料

1 0
原创粉丝点击