codecamp

变量命名

  • 标准变量采用驼峰式命名(除了对象的属性外,主要是考虑到 cgi 返回的数据)
  • ID在变量名中全大写
  • URL在变量名中全大写
  • Android在变量名中大写第一个字母
  • iOS在变量名中小写第一个,大写后两个字母
  • 常量全大写,用下划线连接
  • 构造函数,大写第一个字母
  • jquery对象必须以$开头命名

示例代码

var thisIsMyName;


var goodID;


var reportURL;


var AndroidVersion;


var iOSVersion;


var MAX_COUNT = 10;


function Person(name) {
    this.name = name;
}


// not good
var body = $('body');


// good
var $body = $('body');
文档注释
变量声明
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

编辑器配置和构建检查

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }