javascript编程杂记

1.数组深复制javascript

var obj =[1,2,4];前端

var obj2 = obj.slice(0);vue

2.vue-resource对params参数(get请求)作处理java

若是params中属性为undefined或{}或[],则自动delete该属性后发给后端git

为null则会转化为''github

例 :后端

get请求参数为 {a:null,b:undefined,c:{},d:[],e:122}数组

最后后台接受到的多是babel

{a:'',e:122}vue-resource

3.getComputedStyle是一个能够获取当前元素全部最终使用的CSS属性。

4.add(1,2,3)(2)

function add(...arg){
                let i = 0;
                let len = arg.length;
                add.p = add.p||0;
                for(;i<len;i++){
                    add.p += arg[i];
                };
                add.toString = function(){
                    return add.p;
                }
                return add;
            }

 

5.前端经过_id获取日期

var timestamp = _id.toString().substring( 0, 8 ); var date = new Date( parseInt( timestamp, 16 ) * 1000 );

6.VUE项目中经过引入babel-plugin-transform-vue-jsx实现jsx语法

 
export default {
    name:'anchored-heading',
    render(createElement){
        return (<div>{this.$slots.default}</div>);
    }
} 

 7.vue select问题总结

<select v-model="event_status" class="form-control">
    <option value="" selected>所有</option>//选中,event_status值为空字符串''
  <option :value="" selected>所有</option>//若选中,event_status值为undefined <option v-for="item in activityStatus" :value="item.status"> {{ item.content }} </option> </select>

 8.instanceof 与 isprototypeof用法

[] instanceof Object // true
Object.prototype.isprototypeof([]) //true function对象的原型,也是引用类型
var a = new String('222');
a instanceof Object //true


/** * .--, .--, * ( ( \.---./ ) ) * '.__/o o\__.' * {= ^ =} * > - < * / \ * // \\ * //| . |\\ * "'\ /'"_.-~^`'-. * \ _ /--' ` * ___)( )(___ * (((__) (__))) 高山仰止,景行行止.虽不能至,心向往之。 */