Git Product home page Git Product logo

mixin.js's Introduction

mixin.js Build Status

mixin([deep], target, object1, [objectN])

用一个或多个其他对象来扩展一个对象,返回被扩展的对象。
如果第一个参数设置为true,则返回一个深层次的副本,递归地复制找到的任何对象。否则的话,副本会与原对象共享结构。未定义的属性将不会被复制,然而从对象的原型继承的属性将会被复制。

安装

$ npm install mixin.js --save

使用说明

外链形式

<script type="text/javascript" src="mixin.js"></script>

<script>
    var target = {x: {y: 1, z: 3}};
    var source = {x: {y: 2}, z: 2};
    var obj1 = mixin(target, source); // {x: {y: 2}, z: 2}

    var target = {x: {y: 1, z: 3}};
    var source = {x: {y: 2}, z: 2};
    var obj2= mixin(true, target, source); // {x: {y: 2, z: 3}, z: 2}
</script>

Node端

var mixin = require('mixin.js');

var target = {x: {y: 1, z: 3}};
var source = {x: {y: 2}, z: 2};
var obj1 = mixin(target, source);
// 结果: {x: {y: 2}, z: 2}

var target = {x: {y: 1, z: 3}};
var source = {x: {y: 2}, z: 2};
var obj2= mixin(true, target, source);
// 结果: {x: {y: 2, z: 3}, z: 2}

API

mixin([deep], target, object1, [objectN])

  • deep: 如果设为true,则递归合并。
  • target: 待修改对象。
  • object1: 待合并到第一个对象的对象。
  • objectN: 待合并到第一个对象的对象。

License:

MIT

mixin.js's People

Contributors

381510688 avatar

Stargazers

 avatar 唐道海 avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.