!operation 使用示例

API封装文档
@.merge 规范化与合并数据

var objA = {
    "plus": 10,
    "multiply": 10,
    "and": true,
    "or": true,
    "xor": 10,
    "max": 10,
    "min": 10,
    "multicall": function(){console.log(123)},
    "concat": [1,2,3],
    "union": [1,2,3],
    "merge": {
        a: 1,
        b: 2,
        c: 3
    },
    "overwrite": 10,
    "assign": {
        a: 1,
        b: 2,
        c: 3
    }
};

var objB = {
    "plus": 20,
    "multiply": 20,
    "and": false,
    "or": false,
    "xor": 20,
    "max": 20,
    "min": 20,
    "multicall": function(){console.log(456)},
    "concat": [4, 5, 6],
    "union": [4, 5, 6],
    "merge": {
        a: 4,
        b: 5,
        c: 6
    },
    "overwrite": 20,
    "assign": {
        a: 4,
        b: 5,
        c: 6
    }
};

var result = @.merge.advanced({
    "plus":{
        "!valueType": "number",
        "!operation": "plus"
    },
    "multiply": {
        "!valueType": "number",
        "!operation": "multiply"
    },
    "and": {
        "!valueType": "boolean",
        "!operation": "and"
    },
    "or": {
        "!valueType": "boolean",
        "!operation": "or"
    },
    "xor": {
        "!valueType": "number",
        "!operation": "xor"
    },
    "max": {
        "!valueType": "number",
        "!operation": "max"
    },
    "min": {
        "!valueType": "number",
        "!operation": "min"
    },
    "multicall": {
        "!valueType": "function",
        "!operation": "multicall"
    },
    "concat": {
        "!valueType": "array",
        "!operation": "concat"
    },
    "union": {
        "!valueType": "array",
        "!operation": "union"
    },
    "merge": {
        "!valueType": "object",
        "!operation": "merge"
    },
    "overwrite": {
        "!valueType": "number",
        "!operation": "overwrite"
    },
    "assign": {
        "!valueType": "object",
        "!operation": "assign"
    }
}, objA, objB);

console.log(result);
result.multicall();

//输出内容
//>{ plus: 30,
//>  multiply: 200,
//>  and: false,
//>  or: true,
//>  xor: 30,
//>  max: 20,
//>  min: 10,
//>  multicall: [Function],
//>  concat: [ 1, 2, 3, 4, 5, 6 ],
//>  union: [ 1, 2, 3, 4, 5, 6 ],
//>  merge: { a: 4, b: 5, c: 6 },
//>  overwrite: 20,
//>  assign: { a: 4, b: 5, c: 6 } }
//>456
//>123

需要注意的是,使用"!operation"设置时必须同时设置"!valueType",不同类型的数据所能进行的"!operation"设置也不同,具体可参考下表:

valueTypeplusmultiplyandorxormaxminmulticallconcatunionmergeoverwriteassign
boolean---------------------------------------------------
number----------------------------
string-----------------------------------------------
buffer---------------------------------------------------
date-------------------------------------------------
regex-----------------------------------------------------------
function------
array--------------------------------------
array-autoindex--------------------------------------
object---------------------------------------------
最后更新时间:2018年11月7日 11:12:08