数组方法

==判断是否是数组方法:==

  • value instanseof Array 多框架之间创建数组,传递数组后,具有不同的构造函数
  • Array.isArray(value) ECMAScript5引入

==转换方法==

  • Array.valueOf() 返回 数组
  • Array.toString 返回用逗号隔开的数组元素组合成的字符串 如“1,2,3”
  • Array.join() 返回使用传入值隔开的数组元素组合成的字符串 (缺省值情况使用逗号)

———-update in 2017年10月25日23:36:14

解决高度百分比,标题固定高度的策略

内容物可以设置 position:absolute,然后top:0;bottom:0. 内容物高度会自动计算(同样适用于宽度自适应)

node最佳实践

==mean.io==

  • Node.js
  • Angular4 web starter
  • MongoDB Express Innograph (uses GraphQLfor schema standartization)
  • Bit - (Manages js components,servicesand schemas)

盒子border间隙消除

margin设置为border的宽度负数值
example:

1
2
border:1px solid #d0d0d0;
margin:-1px;

jquery绑定未来元素

1
$('body').on('click','.futureNode',function(){});

callback实现发布、订阅者模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function Publisher(){
this.subscribers=[];
}
Publisher.prototype.deliver=function(data){
this.subscribers.forEach(function(fn){
fn.fire(data);
})
return this;
}

function Observe(callback){
this.fire=callback;
}
Observe.prototype.subscribe=function(publisher){
var that=this;
var alreadyExist=publisher.subscribers.some(function(el){
return el.fire===that.fire;
});
if(!alreadyExist){
publisher.subscribers.push(this);
}
console.log(publisher,publisher.subscribers);
return this;
}

/*用法*/
var publisher1=new Publisher();
var observe1=new Observe(function(n){
console.log("收到消息,消息是:",n);
});

observe1.subscribe(publisher1);

publisher1.deliver("消息1");
publisher1.deliver("消息2");
publisher1.deliver("消息3");

原理:发布者存储订阅者对象,订阅者构造函数里接收发布者对存储对象的回调;

———-update in 2017年12月5日00:07:33