Skip to content

Instantly share code, notes, and snippets.

@mizhdi
mizhdi / react.js
Created February 12, 2015 00:44
react
// first component
var CommentBox = React.creatClass({
render: function() {
return (
<div className="commentBox">
Hello, world!
</div>
);
}
@mizhdi
mizhdi / patterns.js
Last active August 29, 2015 14:14
javascript patterns
// 外观模式
//
// 外观模式是一种很简单的模式,它只是为对象提供了更多的可供选择的接口。
// 使方法保持短小而不是处理太多的工作是一种很好的实践。
// 在这种实践的指导下,你会有一大堆的方法,而不是一个有着非常多参数的uber方法。
// 有些时候,两个或者更多的方法会经常被一起调用。
// 在这种情况下,创建另一个将这些重复调用包裹起来的方法就变得意义了。
var myevent = {
// ……
@mizhdi
mizhdi / ng.js
Last active October 9, 2018 00:17
angular
app.factory('EventBus', function() {
var EventMap = [];
var EventBus = {
on: function(eventType, handler) {
if (!EventMap[eventType]) {
EventMap[eventType] = [];
}
@mizhdi
mizhdi / util.js
Last active August 29, 2015 14:13
js:util
// 禁止iOS浏览器的橡皮筋效果,但是实例中会禁止掉链接的事件,也可以在body上加ontouchmove="event.preventDefault()"
$(document).ready(function(){
function stopScrolling( touchEvent ) {
touchEvent.preventDefault();
}
document.addEventListener( 'touchstart' , stopScrolling , false );
document.addEventListener( 'touchmove' , stopScrolling , false );
});
//判断是否为android,BlackBerry,ios,windows
@mizhdi
mizhdi / util.js
Last active August 29, 2015 14:13
util
// 禁止iOS浏览器的橡皮筋效果,但是实例中会禁止掉链接的事件,也可以在body上加ontouchmove="event.preventDefault()"
$(document).ready(function(){
function stopScrolling( touchEvent ) {
touchEvent.preventDefault();
}
document.addEventListener( 'touchstart' , stopScrolling , false );
document.addEventListener( 'touchmove' , stopScrolling , false );
});
//判断是否为android,BlackBerry,ios,windows
@mizhdi
mizhdi / tool.js
Last active August 29, 2015 14:12
常用j s
// 1
var htmlSurpriseTab = [
'<div>',
'<button id="lucky-draw">Lucky Draw</button>',
'</div>'
].join('');
// 2
actionList[actionName] && actionList[actionName].call(this,event);