1、js里面有哪些数据类型
number boolean string null undefined NaN Symbol
Object Array Map Set
2、null undefined
3、js里面数据的深拷贝如何实现
a.Object.assign()
b.JSON.stringfg(), JSON.parse()
c.递归拷贝
function deepClone (obj) {
var result = {}
var i
if (Object.prototype.toString(obj) === 'Object object') {
for (i in obj) {
if (Object.prototype.toString(obj[i]) === 'Object object'){
result[i] = deepClone(obj[i])
} else {
result[i] = obj[i]
}
}
}
return result
}
4、promise 和 settimeout,运行的机制有什么区别
setTimeout(function(){console.log(1)},0);
new Promise(function(resolve){
console.log(2)
for( var i=0 ; i<10000 ; i++ ){
i==9999 && resolve()
}
console.log(3)
}).then(function(){
console.log(4)
});
console.log(5);
// 2 3 5 4 1
5、react 组件分为哪些类型、生命周期有哪些
constructor compontWillMount compontDidMount compontWillUpdate compontDidUpdate
compontWillReciveProps compontShouldUpdate compontWillUnmount
getDrived... snap
6、Purecomponent 和 Component区别是什么
Purecomponent 自带compontShouldUpdate 方法的判断
7、redux 单向数据流,由哪些部分组成
action(dispath) reducer Store subScribe
实现按钮点击后,更新“counter” 显示内容加1减1的代码。
<body>
<div id="counter"></div>
<button id="addBtn">+</button>
<button id="minusBtn">-</button>
</body>
<script type="text/javascript">
var ADD = 'ADD'
var MINUS = 'MINUS'
var counter = 0
var reducer = function (action) {
switch(action){
case ADD:
return counter++
case MINUS:
return counter--
}
}
var Store = {
counter: 0
}
Object.createProperty('counter', Store, {
set: function(){
},
get: function(){
return this.counter
}
})
var val = ('#addBtn').on('click', function(){
val.html(reducer(ADD))
})
$('#minusBtn').on('click', function(){
val.html(reducer(MINUS))
})
</script>
8、数组 a、b 合并后并去重
let a = ['a','ab',......];
let b = ['c','cd','a'......]
function (a, b) {
var result
result = Array.from(new Set(a.concat(b)))
return result
}
function quchong (arr) {
// var result = []
var result = {}
// arr.forEach(function(item){
// if (result.indexOf(item)<0){
// result.push(item)
// }
// })
arr.forEach(function(item){
if (!result[item]){
result[item] = 1
}
})
return Object.keys(result)
}
9、react高阶组件, 加一个左右10px
class Gaojie extends Componet {
construtor(props){
super(props)
}
render () {
let {child} = this.props
return <div style={{padding: '0 10px'}}><child ...this.props /></div>
}
}