当前位置: 首页 > 编程日记 > 正文

JavaScript最全编码规范

转载: JavaScript最全编码规范

类型

●基本类型:访问基本类型时,应该直接操作类型值

●string
●number
●boolean
●null
●undefined

var foo = 1;
var bar = foo;
bar = 9;
console.log(foo, bar); // => 1, 9

●复合类型:访问复合类型时,应该操作其引用

●object
●array
●function

var foo = [1, 2];
var bar = foo;
bar[0] = 9;
console.log(foo[0], bar[0]); // => 9, 9

对象

●使用字面量语法创建对象

// bad
var item = new Object();// good
var item = {};

●不要使用保留字,在IE8中不起作用,更多相关信息

// bad
var superman = {
default: { clark: 'kent' },
private: true
};// good
var superman = {
defaults: { clark: 'kent' },
hidden: true
};

●使用易读的同义词代替保留字

// bad
var superman = {
class: 'alien'
};// bad
var superman = {
klass: 'alien'
};// good
var superman = {
type: 'alien'
};

数组

●使用字面量语法创建数组

// bad
var items = new Array();// good
var items = [];

●添加数组元素时,使用push而不是直接添加

var someStack = [];// bad
someStack[someStack.length] = 'abracadabra';// good
someStack.push('abracadabra');

●需要复制数组时,可以使用slice,jsPerf的相关文章

var len = items.length;
var itemsCopy = [];
var i;// bad
for (i = 0; i < len; i++) {
itemsCopy[i] = items[i];
}// good
itemsCopy = items.slice();

●使用slice将类数组对象转为数组

function trigger() {
var args = Array.prototype.slice.call(arguments);
...
}

字符串

●对字符串使用单引号

// bad
var name = "Bob Parr";// good
var name = 'Bob Parr';// bad
var fullName = "Bob " + this.lastName;// good
var fullName = 'Bob ' + this.lastName;

●超过80个字符的字符串应该使用字符串连接符进行跨行

●注意:对长字符串过度使用连接符将会影响性能。相关的文章和主题讨论: jsPerf & Discussion.

// bad
var errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';// bad
var errorMessage = 'This is a super long error that was thrown because \
of Batman. When you stop to think about how Batman had anything to do \
with this, you would get nowhere \
fast.';// good
var errorMessage = 'This is a super long error that was thrown because ' +
'of Batman. When you stop to think about how Batman had anything to do ' +
'with this, you would get nowhere fast.';

●以编程方式创建字符串的时应该使用Array的join方法而不是通过连接符,尤其是在IE中:jsPerf.

var items;
var messages;
var length;
var i;messages = [{
state: 'success',
message: 'This one worked.'
}, {
state: 'success',
message: 'This one worked as well.'
}, {
state: 'error',
message: 'This one did not work.'
}];length = messages.length;// bad
function inbox(messages) {
items = '<ul>';for (i = 0; i < length; i++) {
items += '<li>' + messages[i].message + '</li>';
}return items + '</ul>';
}// good
function inbox(messages) {
items = [];for (i = 0; i < length; i++) {
items[i] = '<li>' + messages[i].message + '</li>';
}return '<ul>' + items.join('') + '</ul>';
}

函数

●函数表达式

// anonymous function expression
var anonymous = function() {
return true;
};// named function expression
var named = function named() {
return true;
};// immediately-invoked function expression (IIFE)
(function() {
console.log('Welcome to the Internet. Please follow me.');
})();

●不要在非函数块中(if, while, etc)声明函数,尽管浏览器允许你分配函数给一个变量,但坏消息是,不同的浏览器用不同的方式解析它

●注意:ECMA-262把块定义为一组语句,但函数声明不是一个语句:Read ECMA-262’s note on this issue.

// bad
if (currentUser) {
function test() {
console.log('Nope.');
}
}// good
var test;
if (currentUser) {
test = function test() {
console.log('Yup.');
};
}

●不要命名一个参数为arguments,否则它将优先于传递给每个函数作用域中的arguments对象,

// bad
function nope(name, options, arguments) {
// ...stuff...
}// good
function yup(name, options, args) {
// ...stuff...
}

属性

●使用点表示法访问属性

var luke = {
jedi: true,
age: 28
};// bad
var isJedi = luke['jedi'];// good
var isJedi = luke.jedi;

●用变量访问属性时要使用下标表示法([])

var luke = {
jedi: true,
age: 28
};function getProp(prop) {
return luke[prop];
}var isJedi = getProp('jedi');

变量

●总是使用var声明变量,不然其将变为全局变量。我们要想办法避免全局空间污染

// bad
superPower = new SuperPower();// good
var superPower = new SuperPower();

●使用var声明每个变量,这样很容易添加新的变量声明,而不用去担心用a;替换a,

// bad
var items = getItems(),
goSportsTeam = true,
dragonball = 'z';// bad
// (compare to above, and try to spot the mistake)
var items = getItems(),
goSportsTeam = true;
dragonball = 'z';// good
var items = getItems();
var goSportsTeam = true;
var dragonball = 'z';

●最后声明未赋值的变量,这对于你需要根据之前已经赋值的变量对一个变量进行赋值时是很有帮助的

// bad
var i, len, dragonball,
items = getItems(),
goSportsTeam = true;// bad
var i;
var items = getItems();
var dragonball;
var goSportsTeam = true;
var len;// good
var items = getItems();
var goSportsTeam = true;
var dragonball;
var length;
var i;

●在作用域顶端对变量赋值,这有助于避免变量声明问题和与声明提升相关的问题

// bad
function() {
test();
console.log('doing stuff..');//..other stuff..var name = getName();if (name === 'test') {
return false;
}return name;
}// good
function() {
var name = getName();test();
console.log('doing stuff..');//..other stuff..if (name === 'test') {
return false;
}return name;
}// bad
function() {
var name = getName();if (!arguments.length) {
return false;
}return true;
}// good
function() {
if (!arguments.length) {
return false;
}var name = getName();return true;
}

声明提升

●变量声明是在作用域的顶端,但是赋值没有

// we know this wouldn't work (assuming there
// is no notDefined global variable)
function example() {
console.log(notDefined); // => throws a ReferenceError
}// creating a variable declaration after you
// reference the variable will work due to
// variable hoisting. Note: the assignment
// value of `true` is not hoisted.
function example() {
console.log(declaredButNotAssigned); // => undefined
var declaredButNotAssigned = true;
}// The interpreter is hoisting the variable
// declaration to the top of the scope,
// which means our example could be rewritten as:
function example() {
var declaredButNotAssigned;
console.log(declaredButNotAssigned); // => undefined
declaredButNotAssigned = true;
}

●匿名表达式能提升他们的变量名,但不能提升函数赋值

function example() {
console.log(anonymous); // => undefinedanonymous(); // => TypeError anonymous is not a functionvar anonymous = function() {
console.log('anonymous function expression');
};
}

●命名函数表达式会提升变量名,而不是函数名或者函数体

function example() {
console.log(named); // => undefinednamed(); // => TypeError named is not a functionsuperPower(); // => ReferenceError superPower is not definedvar named = function superPower() {
console.log('Flying');
};
}// the same is true when the function name
// is the same as the variable name.
function example() {
console.log(named); // => undefinednamed(); // => TypeError named is not a functionvar named = function named() {
console.log('named');
}
}

●函数声明会提升变量名和函数体

function example() {
superPower(); // => Flyingfunction superPower() {
console.log('Flying');
}
}

更多信息指引:JavaScript Scoping & Hoisting by Ben Cherry.

比较运算符&相等

●使用===和!==代替==和!=

●比较运算符进行计算时会利用ToBoolean方法进行强制转换数据类型,并遵从一下规则

●Objects的计算值是true
●Undefined的计算值是false
●Boolean的计算值是boolean的值
●Numbers如果是-0,+0或者NaN,则计算值是false,反之是true
●Strings如果是空,则计算值是false,反之是true

if ([0]) {
// true
// An array is an object, objects evaluate to true
}

●使用快捷方式

// bad
if (name !== '') {
// ...stuff...
}// good
if (name) {
// ...stuff...
}// bad
if (collection.length > 0) {
// ...stuff...
}// good
if (collection.length) {
// ...stuff...
}

语句块

●对多行的语句块使用大括号

// bad
if (test)
return false;// good
if (test) return false;// good
if (test) {
return false;
}// bad
function() { return false; }// good
function() {
return false;
}

●对于使用if和else的多行语句块,把else和if语句块的右大括号放在同一行

// bad
if (test) {
thing1();
thing2();
}
else {
thing3();
}// good
if (test) {
thing1();
thing2();
} else {
thing3();
}

注释

●多行注释使用/** … */,需包含一个描述、所有参数的具体类型和值以及返回值

// bad
// make() returns a new element
// based on the passed in tag name
//
// @param {String} tag
// @return {Element} element
function make(tag) {// ...stuff...return element;
}// good
/**
* make() returns a new element
* based on the passed in tag name
*
* @param {String} tag
* @return {Element} element
*/
function make(tag) {// ...stuff...return element;
}

●单行注释使用//,把单行注释放在语句的上一行,并且在注释之前空一行

// bad
var active = true;  // is current tab// good
// is current tab
var active = true;// bad
function getType() {
console.log('fetching type...');
// set the default type to 'no type'
var type = this._type || 'no type';return type;
}// good
function getType() {
console.log('fetching type...');// set the default type to 'no type'
var type = this._type || 'no type';return type;
}

●如果你指出的问题需要重新定位或者提出一个待解决的问题需要实现,给注释添加FIXME or TODO 前缀有利于其他开发者快速理解。这些注释不同于通常的注释,因为它们是可实施的。这些实施措施就是FIXME -- need to figure this out or TODO -- need to implement.

●使用// FIXME:给一个问题作注释

function Calculator() {// FIXME: shouldn't use a global here
total = 0;return this;
}

●使用//TODO:给问题解决方案作注释

function Calculator() {// TODO: total should be configurable by an options param
this.total = 0;return this;
}

空白

●使用软制表符设置两个空格

// bad
function() {
∙∙∙∙var name;
}// bad
function() {
∙var name;
}// good
function() {
∙∙var name;
}

●在左大括号之前留一个空格

// bad
function test(){
console.log('test');
}// good
function test() {
console.log('test');
}// bad
dog.set('attr',{
age: '1 year',
breed: 'Bernese Mountain Dog'
});// good
dog.set('attr', {
age: '1 year',
breed: 'Bernese Mountain Dog'
});

●在控制语句中(if, while etc),左括号之前留一个空格。函数的参数列表之前不要有空格

// bad
if(isJedi) {
fight ();
}// good
if (isJedi) {
fight();
}// bad
function fight () {
console.log ('Swooosh!');
}// good
function fight() {
console.log('Swooosh!');
}

●用空白分隔运算符

// bad
var x=y+5;// good
var x = y + 5;

●用一个换行符结束文件

// bad
(function(global) {
// ...stuff...
})(this);
// bad
(function(global) {
// ...stuff...
})(this);↵
↵
// good
(function(global) {
// ...stuff...
})(this);↵

●当调用很长的方法链时使用缩进,可以强调这行是方法调用,不是新的语句

// bad
$('#items').find('.selected').highlight().end().find('.open').updateCount();// bad
$('#items').
find('.selected').
highlight().
end().
find('.open').
updateCount();// good
$('#items')
.find('.selected')
.highlight()
.end()
.find('.open')
.updateCount();// bad
var leds = stage.selectAll('.led').data(data).enter().append('svg:svg').classed('led', true)
.attr('width',  (radius + margin) * 2).append('svg:g')
.attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
.call(tron.led);// good
var leds = stage.selectAll('.led')
.data(data)
.enter().append('svg:svg')
.classed('led', true)
.attr('width',  (radius + margin) * 2)
.append('svg:g')
.attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
.call(tron.led);

●在语句块和下一个语句之前留一个空行

// bad
if (foo) {
return bar;
}
return baz;// good
if (foo) {
return bar;
}return baz;// bad
var obj = {
foo: function() {
},
bar: function() {
}
};
return obj;// good
var obj = {
foo: function() {
},bar: function() {
}
};return obj;

逗号

●不要在语句前留逗号

// bad
var story = [
once
, upon
, aTime
];// good
var story = [
once,
upon,
aTime
];// bad
var hero = {
firstName: 'Bob'
, lastName: 'Parr'
, heroName: 'Mr. Incredible'
, superPower: 'strength'
};// good
var hero = {
firstName: 'Bob',
lastName: 'Parr',
heroName: 'Mr. Incredible',
superPower: 'strength'
};

●不要有多余逗号:这会在IE6、IE7和IE9的怪异模式中导致一些问题;同时,在ES3的一些实现中,多余的逗号会增加数组的长度。在ES5中已经澄清(source)

// bad
var hero = {
firstName: 'Kevin',
lastName: 'Flynn',
};var heroes = [
'Batman',
'Superman',
];// good
var hero = {
firstName: 'Kevin',
lastName: 'Flynn'
};var heroes = [
'Batman',
'Superman'
];

分号

●恩,这也是规范一部分

// bad
(function() {
var name = 'Skywalker'
return name
})()// good
(function() {
var name = 'Skywalker';
return name;
})();// good (guards against the function becoming an argument when two files with IIFEs are concatenated)
;(function() {
var name = 'Skywalker';
return name;
})();

类型分配&强制转换

●执行强制类型转换的语句。

●Strings:

//  => this.reviewScore = 9;// bad
var totalScore = this.reviewScore + '';// good
var totalScore = '' + this.reviewScore;// bad
var totalScore = '' + this.reviewScore + ' total score';// good
var totalScore = this.reviewScore + ' total score';

●使用parseInt对Numbers进行转换,并带一个进制作为参数

var inputValue = '4';// bad
var val = new Number(inputValue);// bad
var val = +inputValue;// bad
var val = inputValue >> 0;// bad
var val = parseInt(inputValue);// good
var val = Number(inputValue);// good
var val = parseInt(inputValue, 10);

●无论出于什么原因,或许你做了一些”粗野”的事;或许parseInt成了你的瓶颈;或许考虑到性能,需要使用位运算,都要用注释说明你为什么这么做

// good
/**
* parseInt was the reason my code was slow.
* Bitshifting the String to coerce it to a
* Number made it a lot faster.
*/
var val = inputValue >> 0;

●注意:当使用位运算时,Numbers被视为64位值,但是位运算总是返回32位整型(source)。对于整型值大于32位的进行位运算将导致不可预见的行为。Discussion.最大的有符号32位整数是2,147,483,647

2147483647 >> 0 //=> 2147483647
2147483648 >> 0 //=> -2147483648
2147483649 >> 0 //=> -2147483647

●Booleans:

var age = 0;// bad
var hasAge = new Boolean(age);// good
var hasAge = Boolean(age);// good
var hasAge = !!age;

命名规范

●避免单字母名称,让名称具有描述性

// bad
function q() {
// ...stuff...
}// good
function query() {
// ..stuff..
}

●当命名对象、函数和实例时使用骆驼拼写法

// bad
var OBJEcttsssss = {};
var this_is_my_object = {};
function c() {}
var u = new user({
name: 'Bob Parr'
});// good
var thisIsMyObject = {};
function thisIsMyFunction() {}
var user = new User({
name: 'Bob Parr'
});

●当命名构造函数或类名时,使用驼峰式写法

// bad
function user(options) {
this.name = options.name;
}var bad = new user({
name: 'nope'
});// good
function User(options) {
this.name = options.name;
}var good = new User({
name: 'yup'
});

●命名私有属性时使用前置下划线

// bad
this.__firstName__ = 'Panda';
this.firstName_ = 'Panda';// good
this._firstName = 'Panda';

●保存this引用时使用_this

// bad
function() {
var self = this;
return function() {
console.log(self);
};
}// bad
function() {
var that = this;
return function() {
console.log(that);
};
}// good
function() {
var _this = this;
return function() {
console.log(_this);
};
}

●命名函数时,下面的方式有利于堆栈跟踪

// bad
var log = function(msg) {
console.log(msg);
};// good
var log = function log(msg) {
console.log(msg);
};

●注意:IE8和怪异模式下命名函数表示,戳此:http://kangax.github.io/nfe/

●如果文件作为一个类被导出,文件名应该和类名保持一致

// file contents
class CheckBox {
// ...
}
module.exports = CheckBox;// in some other file
// bad
var CheckBox = require('./checkBox');// bad
var CheckBox = require('./check_box');// good
var CheckBox = require('./CheckBox');

存取器

●对于属性,访问器函数不是必须的

●如果定义了存取器函数,应参照getVal() 和 setVal(‘hello’)格式.

// bad
dragon.age();// good
dragon.getAge();// bad
dragon.age(25);// good
dragon.setAge(25);

●如果属性时boolean,格式应为isVal() or hasVal().

// bad
if (!dragon.age()) {
return false;
}// good
if (!dragon.hasAge()) {
return false;
}

●创建get() and set()函数时不错的想法,但是要保持一致

function Jedi(options) {
options || (options = {});
var lightsaber = options.lightsaber || 'blue';
this.set('lightsaber', lightsaber);
}Jedi.prototype.set = function(key, val) {
this[key] = val;
};Jedi.prototype.get = function(key) {
return this[key];
};

构造函数

●在原型对象上定义方法,而不是用新对象重写它。重写使继承变为不可能:重置原型将重写整个基类

function Jedi() {
console.log('new jedi');
}// bad
Jedi.prototype = {
fight: function fight() {
console.log('fighting');
},block: function block() {
console.log('blocking');
}
};// good
Jedi.prototype.fight = function fight() {
console.log('fighting');
};Jedi.prototype.block = function block() {
console.log('blocking');
};

●方法应该返回this,有利于构成方法链

// bad
Jedi.prototype.jump = function() {
this.jumping = true;
return true;
};Jedi.prototype.setHeight = function(height) {
this.height = height;
};var luke = new Jedi();
luke.jump(); // => true
luke.setHeight(20); // => undefined// good
Jedi.prototype.jump = function() {
this.jumping = true;
return this;
};Jedi.prototype.setHeight = function(height) {
this.height = height;
return this;
};var luke = new Jedi();luke.jump()
.setHeight(20);

●写一个自定义的toString()方法是可以的,只要确保它能正常运行并且不会产生副作用

function Jedi(options) {
options || (options = {});
this.name = options.name || 'no name';
}Jedi.prototype.getName = function getName() {
return this.name;
};Jedi.prototype.toString = function toString() {
return 'Jedi - ' + this.getName();
};

事件

●当在事件对象上附加数据时(无论是DOM事件还是如Backbone一样拥有的私有事件),应传递散列对象而不是原始值,这可以让随后的贡献者给事件对象添加更多的数据,而不必去查找或者更新每一个事件处理程序。举个粟子,不要用下面的方式:

// bad
$(this).trigger('listingUpdated', listing.id);...$(this).on('listingUpdated', function(e, listingId) {
// do something with listingId
});

●应该按如下方式:

// good
$(this).trigger('listingUpdated', { listingId : listing.id });...$(this).on('listingUpdated', function(e, data) {
// do something with data.listingId
});

模块

●模块应该以 ! 开始,这能确保当脚本连接时,如果畸形模块忘记导入,包括最后一个分号,不会产生错误。Explanation

●文件应该以驼峰式命名,放在同名的文件夹中,和单出口的名称相匹配

●定义一个noConflict()方法来设置导出模块之前的版本,并返回当前版本。

●在模块的顶部申明’use strict';

// fancyInput/fancyInput.js!function(global) {
'use strict';var previousFancyInput = global.FancyInput;function FancyInput(options) {
this.options = options || {};
}FancyInput.noConflict = function noConflict() {
global.FancyInput = previousFancyInput;
return FancyInput;
};global.FancyInput = FancyInput;
}(this);

jQuery

●jQuery对象变量使用前缀$

// bad
var sidebar = $('.sidebar');// good
var $sidebar = $('.sidebar');

●缓存jQuery查询

// bad
function setSidebar() {
$('.sidebar').hide();// ...stuff...$('.sidebar').css({
'background-color': 'pink'
});
}// good
function setSidebar() {
var $sidebar = $('.sidebar');
$sidebar.hide();// ...stuff...$sidebar.css({
'background-color': 'pink'
});
}

●使用级联\((‘.sidebar ul’)或父子\)(‘.sidebar > ul’)选择器进行DOM查询。jsPerf

●在范围内使用find进行jQuery对象查询

// bad
$('ul', '.sidebar').hide();// bad
$('.sidebar').find('ul').hide();// good
$('.sidebar ul').hide();// good
$('.sidebar > ul').hide();// good
$sidebar.find('ul').hide();

转载于:https://www.cnblogs.com/andy-zhou/p/5306925.html

相关文章:

源码推荐:collectionView拖拽,仿凤凰FM iOS 局部监听键盘再也不会挡住输入框

UICollectionView拖拽移动单元以及本地保存&#xff08;上传者&#xff1a;dengqi&#xff09; UICollectionView拖拽移动单元以及本地保存&#xff0c;可以保存你上次移动的位置。 仿映客直播导航条&#xff08;上传者&#xff1a;Coolcool&#xff09; 仿映客直播自定义TabBa…

采集练习(一) php 获得全国的小学(数据来自腾讯朋友网)

注&#xff1a;发现腾讯朋友网已经改版&#xff0c;部分参数需要自己获得修改 &#xff01;&#xff01;&#xff01; 年前有个需求获得某省的小学数据&#xff0c;分析了下朋友网的小学学校发现可以获得相关数据。 如获得 湖南省郴州市宜章县的全部小学 发现网页请求的地址…

android 模板方法模式,安卓设计模式(七)模板方法模式

模板方法模式用于固定相关操作的执行流程,将具体实现延迟到子类中该系列其他文章:定义: 定义一个操作中算法的框架,而降一些步骤延迟到子类中,使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤.使用场景:代码重构时,模板方法是经常被用到的,将固定部分提取到父…

solr单机版的搭建

一、solr单机版的搭建 1.运行环境 solr 需要运行在一个Servlet容器中&#xff0c;Solr4.10.3要求jdk使用1.7以上&#xff0c;Solr默认提供Jetty&#xff08;ja&#xff09;&#xff0c;本教va写的Servlet容器程使用Tocmat作为Servlet容器&#xff0c;环境如下&#xff1a; Solr…

android5.0后新特性修改标题头,Android5.0中Material Design的新特性

Material Design简介Material Design是谷歌新的设计语言&#xff0c;谷歌希望寄由此来统一各种平台上的用户体验&#xff0c;Material Design的特点是干净的排版和简单的布局&#xff0c;以此来突出内容。Material Design对排版、材质、配色、光效、间距、文字大小、交互方式、…

MFCard:易用的信用卡支付集成类库

原文链接&#xff1a;https://github.com/MobileFirstInc/MFCardMFCard&#xff1a;易用的信用卡支付集成类库。# 为开源点赞# —— 由 SwiftLanguage 分享MFCard is an awesome looking Credit Card input & validation control. Written in Swift 3. Demo Usage First St…

Castle ActiveRecord学习(四)延迟加载、分页查询、where条件

一、延迟加载 //用户发布的主题&#xff0c;一对多&#xff1b;Table&#xff1a;外键表&#xff1b;ColumnKey&#xff1a;外键&#xff1b;Lazy&#xff1a;延迟加载&#xff1b;Cascade&#xff1a;级联操作&#xff08;级联删除&#xff09;[HasMany(typeof(ThemeInfo), Ta…

系统吞吐量(TPS)、用户并发量、性能测试概念和公式(转载)

原文地址&#xff1a;http://www.ha97.com/5095.html PS&#xff1a;下面是性能测试的主要概念和计算公式&#xff0c;记录下&#xff1a; 一&#xff0e;系统吞度量要素&#xff1a; 一个系统的吞度量&#xff08;承压能力&#xff09;与request对CPU的消耗、外部接口、IO等等…

android layout后还原位置,Android图片框架photoview如何记住所有状态并还原,包括缩放度,缩放后的移动的距离等等...

Android图片框架photoview如何记住状态并还原&#xff0c;包括缩放度&#xff0c;缩放后的移动的距离等等,尝试了好多方法都没有作用。private void generateImages() {for (int i 0; i < imagesEntities.size(); i) {// PhotoViewAttacher attacher;final ImagesEntity en…

Shiro安全登录框架

环境准备 本文使用Maven构建&#xff0c;因此需要一点Maven知识。首先准备环境依赖&#xff1a; Java代码 <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <…

iOS自动签名打包(xcodebuild)----常用

iOS自动打包主要用xcodebuild命令, 在终端输入xcodebuild --help可以查看xcodebuild的参数。 xcodebuild具体语法&#xff1a; 无workspace的工程 xcodebuild [-project name.xcodeproj] [[-target targetname] … | -alltargets] [-configuration configurationname] [-sdk [s…

设计模式解析(五)——几种设计模式之Facade和Adapter

由于个人时间原因&#xff0c;无法详细描述这些模式&#xff0c;暂且记录下来以后慢慢补充详细。 Facade模式 Facade模式&#xff1a;关键特征 意图希望简化原有系统的使用方式。需要定义自己的接口。问题只需使用某个复杂系统的子集&#xff0c;或者&#xff0c;需要以一种特殊…

android level list,Android Drawable (levle List selector layer List)

8种机械键盘轴体对比本人程序员&#xff0c;要买一个写代码的键盘&#xff0c;请问红轴和茶轴怎么选&#xff1f;管理大量备选可绘制对象的可绘制对象&#xff0c;每个可绘制对象都分配有最大的备选数量。使用 setLevel() 设置可绘制对象的级别值会加载级别列表中 android:maxL…

人脸检测流程及正负样本下载

源地址&#xff1a;http://www.thinkface.cn/thread-146-1-4.html 人脸检测做训练当然可以用OpenCV训练好的xml&#xff0c;但是岂止于此。我们也要动手做&#xff01;~首先是样本的选取。样本的选取很重要&#xff0c;找了很久才发现几个靠谱的。人脸样本&#xff1a;http://w…

源码推荐:仿写映客直播 ,快速切换主题 ,星星评分控件,表格样式,可以横向移动的表格, 仿微信键盘-

仿写映客直播&#xff08;上传者&#xff1a;五仁月饼&#xff09; 工作之余写的,基于IJKPlayer播放&#xff0c;对内存做了处理。目前已完成直播列表和直播间的搭建&#xff0c;后续还会慢慢完善。 项目地址 publishImageAndVideoAnsRecord&#xff08;上传者&#xff1a;zlj5…

希尔排序——算法系列

希尔排序&#xff1a; 插入排序的升级版&#xff0c;主要采用了分组的策略&#xff0c;采用逐渐减小步长来控制分组的大小&#xff0c;各组内采用插入排序&#xff0c;当步长减小为1的时候&#xff0c;大部分数据都已经有序&#xff0c;所以较插入排序优化了许多。 代码&#x…

android 请求方式有哪些,Android中的几种网络请求方式详解

Android应用经常会和服务器端交互&#xff0c;这就需要手机客户端发送网络请求&#xff0c;下面整理四种常用网络请求方式。java.net包中的HttpURLConnection类Get方式&#xff1a;// Get方式请求public static void requestByGet() throws Exception {String path "http…

Sqlserver的触发器的简单使用

1&#xff0c;触发器有两种 &#xff08;1&#xff09;After触发器&#xff08;之后触发&#xff09; 触发器有个好处&#xff1a;就是你之前有过什么操作他会将你的操作的数据信息完整的保存下来&#xff0c;比如你删过什么信息&#xff0c;如果用触发器&#xff0c;那么删除后…

网络协议OSI、TCP/IP协议、Socket套接字和第三方AsyncSock的使用等解析

一、网络协议定义 1.OSI参考模型:全称(Open System Interconnection), 开放式系统互联参考模型。是一个逻辑上的定义&#xff0c;一个规范&#xff0c;它把网络协议从逻辑上分为七层&#xff0c;只要目的是为解决异种网络互连时所遇到的兼容性问题&#xff0c;其最主要的功能是…

Win8之快速关机

还在纠结如何关机吗&#xff1f;现在教你几招 1、 AltF4快捷键&#xff0c;Windows桌面下按AltF4即可弹出关机菜单&#xff08;保证无任何程序处于被选中状态&#xff0c;可以点击任务栏最右侧 来回到桌面&#xff0c;这时就没问题了&#xff09; 现在怎么关机就不用教了吧。 2…

多键开关 android8.0,手机桌面多键开关(SwitchPro Widget )

7键开关SwitchPro Widget 是款主屏幕窗口小部件工具&#xff0c;可用于开启/关闭多种系统功能&#xff0c;支持多种自定义设置&#xff0c;比原生的电量控制开关好用很多。7键开关SwitchPro Widget并非只有7个按键开关&#xff0c;而是有很多的意思&#xff0c;最多可以设置十几…

程序员取悦女票的正确姿势---Tip1(iOS美容篇)

前言 女孩子都喜欢用美图工具进行图片美容&#xff0c;近来无事时&#xff0c;特意为某人写了个自定义图片滤镜生成器&#xff0c;安装到手机即可完成自定义滤镜渲染照片。app独一无二&#xff0c;虽简亦繁。 JH定律&#xff1a; 魔镜&#xff1a;最漂亮的女人是你老婆 魔镜&am…

MySQL的安装配置(win7 64-bit)

MySQL的安装配置(win7 64-bit) 转&#xff0c;整理。 MySQL 版本是 mysql-noinstall-5.1.66-winx64.zip&#xff08;免安装版&#xff09; mysql-workbench-gpl-5.2.44-win32.msi mysql-connector-java-5.1.22 mysql 配置数据库编码为utf-8&#xff08;my.ini中指定&#xff09…

Sourse Insight使用教程及常见的问题解决办法

1、下载安装 2、创建项目new project(注意不是file-->new ),而是project-->new project,输入项目名称和密码. 3、添加文件&#xff0c;其实就是将你的整个项目文件添加到project中。 4、close就可以打开了。 具体参考道客巴巴一篇文章&#xff1a;Source_Insight教程及技…

android surface 平板,Surface平板能升级安卓4.0吗

Surface平板电脑暂时不能升级安卓4.0。Surface平板电脑x86架构的版本搭载了英特尔Core i5 Ivy Bridge双核处理器&#xff0c;而ARM架构的版本搭载了Nvidia代工的ARM单核处理器。Surface平板电脑采用镁合金机身&#xff0c;具有x86和ARM架构两个版本&#xff0c;x86架构的版本屏…

iOS - 实现映客首页 TabBar 和滑动隐藏 NavBar 和 TabBar

原文链接&#xff1a;http://www.jianshu.com/p/72228667cd7a之前在做直播的时候&#xff0c;参照了映客 App&#xff0c;发现其首页的效果还挺不错&#xff0c;在网上找了一下相关仿映客 App 代码和博客&#xff0c;大部分都是说如何播放直播流和推流&#xff0c;对于 UI 这块…

WinCE项目应用之车载导航

WinCE车载导航系统是我过去几年投入精力比较多的一个项目。我的主要工作内容是BSP的移植、硬件模块的调试和WinCE系统的深度定制。如TDA7415驱动、TDA7415均衡器、慧翰车载蓝牙模块、华为EM730的3G通信模块、四线电阻式触摸屏驱动的优化、3G拨号助手、LCD调试助手、WIFI模块AR6…

记录下,我们平时开发当中不得不知道的HTTP状态码

上面是我对博客园页面加载的时候&#xff0c;获取的AJAX读取资源的截图。 上述列表告诉我们了&#xff0c;返回的HTTP状态码&#xff0c;分为200&#xff08;正常&#xff09;&#xff0c;304&#xff08;不修改&#xff09;和同时返回的资源大小和完成时间等。 这个工具可以很…

rmd文件怎么转换html文件,提取.Rmd文件的html依赖项(包含htmlwidgets)

题我怎样才能创建一个将.Rmd文件(包含htmlwidgets代码)作为输入的函数,并输出一个包含其JavaScript / CSS依赖项的html文件&#xff1f;具体来说,当渲染为html时,临时文件rmarkdown为pandoc的–include-in-header参数生成.细节示例 – myfile.Rmd&#xff1a;This is some text…

教你实现GPUImage【OpenGL渲染原理】

原文出处&#xff1a; 袁峥Seemygo&#xff08;袁峥Seemygo&#xff09; 一、前言 本篇主要讲解GPUImage底层是如何渲染的,GPUImage底层使用的是OPENGL,操控GPU来实现屏幕展示 由于网上OpenGL实战资料特别少&#xff0c;官方文档对一些方法也是解释不清楚&#xff0c;避免广大…