Use the TWIN to solve multi-inheritance in Java
Multiple inheritance allows one to inherit data and code from more than one base class. It is a controversial feature that is claimed to be indispensable by some programmers, but also blamed for problems by others, since it can lead to name clashes, complexity and inefficiency. In most cases, software architectures become cleaner and simpler when multiple inheritance is avoided, but there are also situations where this feature is really needed. If one is programming in a language that does not support multiple inheritance (e.g. in Java), but if one really needs this feature, one has to find a work-around. The Twin pattern — introduced in this paper—provides a standard solution for such cases. It gives one most of the benefits of multiple inheritance while avoiding many of its problems.
JavaScript编码规范 - From Airbnb
类型
- 基本类型 Primitives
- string
- number
- boolean
- null
- undefined
var foo = 1; var bar = foo; bar = 9; console.log(foo, bar); // => 1, 9
- 复合类型 Objects
- 创建对象,使用literal syntax
// bad var item = new Object(); // good var item = {};
- 不要使用保留字reserved words
// 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' };
数组 Arrays
- 创建对象,使用literal syntax
// bad var items = new Array(); // good var items = [];
- 使用push方法
var someStack = []; // bad someStack[someStack.length] = 'abracadabra'; // good someStack.push('abracadabra');
- 需要复制数组时,使用slice
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); ... }