楠持的小铺

做人不卖萌跟咸鱼有什么区别

  • 首页
  • 归档
  • 标签
  • 实验室
  • 关于

链表

发表于 2017-08-05

leetCode中Merge Two Sorted Lists,由此引发温习链表结构在JavaScript中的存储表示

链表

物理上非连续,非顺序的存储结构,数据元素以结点的指针链接次序实现的。生活中例子:自行车的链条
结点: data:存储数据元素的数据域,next是存储下一个结点地址的指针域
┌───┬───┐
│data │next │
└───┴───┘

优点:

  • 克服数组链表需要预先知道数据大小的缺点

缺点:

  • 无法随机读取
  • 增加空间开销,增加了指针开销

单链表

以“结点的序列”表示线性表称作线性链表

单链表

尾节点指针为null

1
2
3
4
function ListNode(value){
this.data = value
this.next = null
}
阅读全文 »

Vue数据传递问题

发表于 2017-07-21

Vue数据传递

2.0中官方文档,API文档-组件

数据父-子

数据

prop:使用prop传递数据,单向数据流,.sync 双向绑定[语法糖:foo="" @update:foo="val => bar = val"].
v-model::value="something" v-on:input="something = arguments[0]"
v-bind

v-bind="$props" 会把object props中的数据绑定都绑定

$props:对象,代表当前组件收到的 props。Vue 示例代理访问到这个 props 对象的属性们

1
2
3
4
<child v-bind="$props"></child>
<child :showHit="showHit" :message="message"></child>

1
2
3
4
5
6
{
props: {
showHit: Boolean,
message: Boolean
},
}

v-bind='Object': 相当于v-bind:ObjectKey="value" ...

v-bind='value': String

阅读全文 »

==和===

发表于 2017-07-20

==和===

1、对于string,number等基础类型,==和===是有区别的

  • 不同类型转换为同一类型的值
  • 比较值

    === 需要比较类型和值

2、对于Array,Object等高级类型,==和===是没有区别的

对存储指针进行比较

3、基础类型与高级类型,==和===是有区别的

1)对于==,高级类型转换为基础类型值,后比较值

1
2
var a = []
a == 0 //true => Number(a) == 0

2)=== ,因为类型不同结果为false

设计模式之观察者[订阅发布模式]

发表于 2017-07-14

设计模式之观察者、订阅发布模式

观察者模式又被称为发布-订阅模式,当一个对象改变同时有需要改变其他对象,并且它不知道需要改变多少对象的同时使用该模式最为合适。代码解耦的工作,耦合的双方都依赖于抽象不依赖具体的。

观察者应该包含3个方法,订阅,退订,发布/通知

实现代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Observe{
constructor(){
this.sub = []
}
add(fn){
this.sub.push(fn)
}
del(fn){
this.sub = this.sub.filter(item=>item!==fn)
}
notify(argument,scope){
scope = scope || window
for(i=0,len=this.sub.length;i<len;i++){
this.sub[i].call(scope,argument)
}
}
}
阅读全文 »

Object.defineProperty

发表于 2017-07-14

Object.defineProperty

API
Object.defineProperty(obj, prop, descriptor)

  • obj:[Object] 目标对象
  • prop:[String] 需要定义或者修改的属性
  • descriptor:[Object] 配置属性 {enumerable,configurable,writable, get,set,value }

enumerable:[Boolean] default:true,true 时 forin是否可枚举
configurable:[Boolean]
value:default:undefined.
writable:[Boolean] default:true
set:[Function] default:undefined
get:[Function] default:undefined

阅读全文 »

vue 使用过程中遇到的问题

发表于 2017-07-09

vue 使用过程中遇到的问题[待整理]

observe data 数据不会随props数据象变化

Vue中props的数据不允许修改,故而采用新变量赋值的方式存储。但会引发一个问题props的数据已经更改,data这得未改

  • 使用Computed

    1
    2
    3
    4
    5
    6
    7
    8
    {
    props:['data1']
    computed:{
    test(){
    return this.data1
    }
    }
    }
  • data + watch

1
2
3
4
5
6
7
8
9
10
11
12
13
{
props:['data1']
data(){
return{
test:this.data1
}
}
watch:{
data1(){
this.test = this.data1
}
}
}

动态增加state数据,获取state数据

在生命中周期渲染中可以发现只有在created状态之前声明的状态才能有双向绑定监听的效果。

1
2
3
4
5
6
7
8
9
10
{
data:{
list:null //标记
},
methods:{
modifyState(state){
this.list = Object.assign({}, state)
}
}
}

阅读全文 »

谈判力

发表于 2017-07-09

程序员大部分人都不善于谈判和表达,我也是其中的典型。这本书是谈判学中的一本入门书籍大纲如下,真正的入门需要深入的学习和生活中反馈学习

脑图

vue 生命周期

发表于 2017-07-08

镇楼–生命周期图

生命周期

调试代码

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
37
38
39
40
41
42
43
44
45
export default {
beforeCreate() {
debugger
console.log('beforeCreate', this)
console.log('this $data', this.$data) //null
},
data() {
debugger
console.log('data Oberserve', this)
return {
message: '测试数据'
}
},
created() {
debugger
console.log('created', this)
console.log('this $data', this.$data) //{message: '测试数据'}
},
beforeMount() {
debugger
console.log('beforeMount', this)
console.log('this $data', this.$el)// <div>{{message}}</div>
},
mounted() {
debugger
console.log('mounted', this)
console.log('this $data', this.$el) //<div>测试数据</div> 挂载
},
beforeUpdate() {
debugger
console.log('beforeUpdate', this)
},
updated() {
debugger
console.log('updated', this)
},
beforeDestroy() {
debugger
console.log('beforeDestroy', this)
},
destroyed() {
debugger
console.log('destroyed', this)
}
}
阅读全文 »

Array reduce

发表于 2017-07-03

Array reduce

API

1
2
arr.reduce([callback,initialValue])
  • callback(prev,current,currentIndex,array)
  • initialValue 可选,第一个参数
阅读全文 »

vue render

发表于 2017-06-30

问题

问题:需要实现一个动态的表单配置,Model配置如下.条件时间比较赶,原有项目利用了elm ui 组件库

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
const config= {
items: [
{
componentName: 'app-select',
type: 'select',
key: 'test',
value: '1',
options: [{
value: '1',
label: '公司新闻'
}, {
value: '2',
label: '新闻列表'
}]
},
{
componentName: 'el-input',
type: 'text',
key: 'test_string',
placeholder: 'test_string'
},
{
componentName: 'el-input-number',
max: 100,
min: 0,
value: '5',
key: 'test_int',
placeholder: 'test_int'
}]
}
cont formData = initFormData(config) //{text_string:''...}

阅读全文 »
12…5
杨建兰

杨建兰

49 文章
17 标签
© 2017 杨建兰
Erstellt mit Hexo
Theme - NexT.Pisces