redux中的middleware

2016-03-27
阅读 2 分钟
1.9k
其中applyMiddleware(...)是一个enhancer。enhancer在redux中的作用会代理createStore方法返回具有增强效果的store.

npm下常用mirror

2016-03-26
阅读 1 分钟
6k
npm {代码...} electron {代码...} phantomjs {代码...} chromedirver {代码...} [链接]

使用duckie为JS做强类型检查

2015-03-14
阅读 3 分钟
4.4k
JS是一门动态类型语言,在定义一个函数时,无法为其进行强类型指定,如: {代码...} 如果没有类型指定的话: 开发者常常不知道一个函数需要什么数据类型。 出现奇怪错误时,给debug造成麻烦。 其实业界已经有两种解决办法: 使用JSDoc对函数进行注释 使用强类型语言编程,最后编译成JS. 首先说第一种,JSDoc的语法规则可...

谈谈FLUX的使用

2015-02-12
阅读 4 分钟
9.2k
提要:本文所展示示例代码,既非JQuery代码,也是不React代码,为介于两者间的,方便行文伪代码。代码意思通过上下文即可理解。 Facebook的Jing Chen同学在2014年的F8上演示了她的FLUX架构。 FLUX的工作流如下: 中央Dispatcher管理所有进来的ACTION。 可以注册任意多个Store处理ACTION. 组件在需要修改数据的时候,发出...

控制反转与双向绑定

2015-02-10
阅读 2 分钟
4.5k
引子 在前端开发中,常常有这样的naive的代码,先是在HTML中定义了页面结构: {代码...} 在有交互时,用js通过其class来取到节点,然后将数据写进去,如$('.order-total').html(300)。 大约在三年前,这种做法在业界还颇为流行,几乎所有的书里,网上教义,都在鼓吹这种分离JS和HTML的行为,认为这么做就是天经地义。 但...

漫谈作坊,MVC,MVVM及FLUX(1)

2015-01-25
阅读 5 分钟
6.5k
篇首语:这将是一系列文章,按心情更新,从作坊开始,简述在前端开发中遇到的一系列问题,以及为了解决类似问题而衍生出的设计模式,看看这些模式是如何解决我们遇到的难题以及相应的好处和不足。

理解reflux中的事件结合

2015-01-20
阅读 2 分钟
13.2k
reflux是一个flux的实现框架,但又在部分概念和实现上与flux的产生了分歧。分歧点主要是为了: 简化Flux的编码量,让机器完成那些重复的体力活。 迈向Reactive Programming,而不是Imperative Programming. 一个重要的分歧点是reflux中取消了flux中的waitFor的概念,取而代之的是: store之间可以相互监听。当一个Store...

用webpack来取代browserify

2015-01-15
阅读 1 分钟
28.4k
本来打算一心跟着browserify走的,但是无奈它的transform机制令人烦躁。今天有这么一个需求,配置了一会,感觉用browserify搞不定。

watchify和browserify

2015-01-13
阅读 2 分钟
8.5k
当开始一个React项目的时候,首要的烦人问题就是,编译。似乎考虑到编译就得去学Grunt脚本,就得去写gulp。虽然会写gulp脚本,但仍然觉得这些事情很没必要也很耗时,而且这种脚本的特点是难以debug,相当费时。是否稍做配置就可以完全编译呢?答案是可以的。

Javascript鸡汤

2015-01-12
阅读 1 分钟
3.7k
Speeding up JavaScript: Working with the DOM 一篇关于如果高效的操作DOM以避免频繁触发reflow的文章。 Repaints and Reflows: Manipulating the DOM responsibly 介绍什么是repaint以及什么是reflow。其引用的文章也值得一读。 ReactJS: Keep Simple. Everything can be a component! by Pedro Nauck 介绍React诸多好...

Promise/A+规范

2014-12-29
阅读 3 分钟
42.5k
Promise表示一个异步操作的最终结果。与Promise最主要的交互方法是通过将函数传入它的then方法从而获取得Promise最终的值或Promise最终最拒绝(reject)的原因。

为什么总有target=_blank?

2014-12-07
阅读 1 分钟
2.2k
源于Browsing Context 的概念,不仅有_blank,还有_parent, _top, _self等。 先留个坑。见示例。

资源加载和页面事件

2014-11-28
阅读 3 分钟
6.1k
domLoading 浏览器开始解析dom树的时间点 domInteractive 表示浏览器已经解析好dom树了。 domContentLoaded 同步的JS已经执行完毕了。 这里需要再解释一点: 由于同步JS会阻塞Dom的解析,因此在有同步JS的情况下,domInteractive和domContentLoaded的区别不大。 如果JS添加了defer属性,那么domInteractive和domContentL...

谈谈eval另一面

2014-06-05
阅读 3 分钟
5k
A direct call to the eval function is one that is expressed as a CallExpression that meets the following two conditions: The Reference that is the result of evaluating the MemberExpression in the CallExpression has an environment record as its base value and its reference name is "eval". The resu...

谈谈Javascript中的delete操作符

2014-05-16
阅读 7 分钟
3.9k
你觉得下列代码中,哪些delete操作能成功?人肉判断一下,不要放进浏览器里执行。 {代码...} 如果上述代码都在strict模式下执行呢,又有哪些操作是成功的呢?如果不清楚的话,往下看。 PS:本文所表述的内容均由规范演译而来,而非通过实验进行推理,代码示例仅用来证明文中阐述内容的正确性,如有疑惑欢迎留言讨论。 de...

文件加载与页面阻塞

2014-05-03
阅读 4 分钟
4.5k
网上关于文件加载与页面阻塞的文章多如牛毛,大致可分类两类: 纯抄(或参考)《高性能javascript》和《高性能网站建设指南》 有测试并有截图和解释,但存在如下问题: 不全面,如可能只提到Chrome是如何加载的(毕竟它的Timeline太好用了) 读者很难重现作者的步骤,一方面是给了一个死链(虽然当时是好的),另一种情况...

谈谈Javascript中的void操作符

2014-04-19
阅读 4 分钟
44.1k
由于JS表达式偏啰嗦,于是最近便开始采用Coffeescript来减轻负担。举个栗子,当我想取屋子里的第一条dog时,首先要判断house对象是否存在,然后再判断house.dogs是否存在,最后取house.dogs[0]。在JS需要这么写

谈谈white-space和word-wrap

2014-04-17
阅读 2 分钟
8.8k
有两个CSS属性我一直在混淆着其意义,今天一并整理掉。 white-space和word-wrap通常用来解决如下问题: 字符串太长,但又不想让其换行,强制其在一行中(如显示代码),如何实现? 单词太长,但如果不折行的话会溢出,我希望它能多行显示。 为什么我明明打了10个空格,可显示出来的只有一个? 为什么我明明敲了10个回车,...

[LeetCode] 链表分区

2014-04-12
阅读 2 分钟
2.9k
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. For example, Given 1->4->3->2->5->2 and x = 3, return 1->2-&g...

[LeetCode] 最小包含字符子串

2014-04-07
阅读 3 分钟
4.4k
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example, S = "ADOBECODEBANC" T = "ABC" Minimum window is "BANC". Note: If there is no such window in S that covers all characters in T, return the emtpy string "". If t...

[LeetCode] 解数独

2014-04-05
阅读 3 分钟
4.6k
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution. A sudoku puzzle... ...and its solution numbers marked in red.

[LeetCode] 搜索已排序的旋转数组

2014-04-04
阅读 2 分钟
4.3k
题目:Search in Rotated Sorted Array Total Accepted: 11248 Total Submissions: 40041 My Submissions

[LeetCode] 合并两个已排序数组

2014-04-03
阅读 2 分钟
3.9k
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

[LeetCode] 生成括号组合

2014-04-02
阅读 2 分钟
6.1k
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "()()()"

[LeetCode] 删除链表的倒数第N个节点

2014-04-02
阅读 2 分钟
6.3k
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Given n will always be valid. Try to do this in ...

[LeetCode] 四数之和

2014-04-02
阅读 3 分钟
3.9k
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a ≤ b ≤ c ≤ d) The solution set must not ...

[LeetCode] 三数之和

2014-04-02
阅读 3 分钟
4.2k
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array S = {-1 2 1 -4}, and target = 1. The sum that is closest ...

[LeetCode] 写一个正则表达式匹配

2014-04-02
阅读 3 分钟
6k
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const char *s, const char *p) Som...

[LeetCode] 判断一个数字是否为回文数

2014-04-01
阅读 2 分钟
20.4k
Determine whether an integer is a palindrome. Do this without extra space.

[LeetCode] 转换字符串为数字

2014-04-01
阅读 3 分钟
5.9k
题目:String to Integer (atoi) Implement atoi to convert a string to an integer. 分析:转换输入字符串为数字,原以为这是一道巨水题,单次提交通过肯定是没问题了,哪知...... 题目要求: 如果前面有空格开头,忽略掉开头的所有空格 如果发现没意义的字符,忽略之,并结束转换。即123ttyw -> 123 考虑负数额 如...