javascript编程杂记

1.数组深复制

var obj =[1,2,4];

var obj2 = obj.slice(0);

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

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

为null则会转化为''

例 :

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

最后后台接受到的可能是

{a:'',e:122}

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

 

posted @ 2016-12-06 14:03  杜培东  阅读(344)  评论(0编辑  收藏  举报