我是JS中"就近声明"以及"允许多次var声明"的拥护者。
我持这样观点源自我对易读性的追求。
看一段代码:
function aFunc() {
for(var i = 0; i < 100; i++) {
doSth(i);
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating | |
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel | |
// MIT license | |
(function() { | |
var lastTime = 0; | |
var vendors = ['ms', 'moz', 'webkit', 'o']; |
// sign up | |
account.signUp('joe@example.com', 'secret'); | |
// sign in | |
account.signIn('joe@example.com', 'secret'); | |
// sign in via oauth | |
account.signInWith('twitter'); | |
// sign out |
// add a new object | |
var type = 'note'; | |
var attributes = {color: 'red'}; | |
store.add(type, attributes) | |
.done(function (newObject) {}); | |
.fail(function (error) {}); | |
// update an existing object | |
var type = 'note'; | |
var id = 'abc4567'; |
// convert a dom element to a PDF and download it | |
convert( $('.invoice') ).to( 'invoice.pdf' ).download() | |
// alternatively | |
download( convert( $('.invoice') ).to( 'invoice.pdf' ) ) | |
// convert another website to a png and show it on the page | |
convert( 'http://exam.pl/page' ).toImage().then( $('.screenshots').append ) | |
// attach a file to an email |
// purchase a product with a credit card | |
purchase('productId') | |
.using( { | |
cc: "4556934156210213", | |
valid: "2016-10", | |
csc: "123" | |
} ) | |
// purchase a product with paypal | |
purchase('productId') |
// Ask the coffee machine at IP 192.168.2.2 to do its job | |
device('192.168.2.2') | |
.do( 'coffee' ) | |
.then( wakeMeUpCallback ) | |
// turn all lights on | |
device.findAll('light').do('turnOn') |
我是JS中"就近声明"以及"允许多次var声明"的拥护者。
我持这样观点源自我对易读性的追求。
看一段代码:
function aFunc() {
for(var i = 0; i < 100; i++) {
doSth(i);
var cv = document.getElementById('cv'); | |
var c = cv.getContext('2d'); | |
var txtDiv = document.getElementById('txt'); | |
var fileBtn = document.getElementById("up-button"); | |
var img = new Image(); | |
img.src = 'a.jpg'; | |
img.onload = init; // 图片加载完开始转换 | |
fileBtn.onchange = getImg; | |
// 根据灰度生成相应字符 |
// ------------ | |
// counterStore.js | |
// ------------ | |
import { | |
INCREMENT_COUNTER, | |
DECREMENT_COUNTER | |
} from '../constants/ActionTypes'; | |
const initialState = { counter: 0 }; |