Giter VIP home page Giter VIP logo

mixin.js's Introduction

使用说明

外链形式

<script src="{{src}}"></script>

<script>
    function A(options){
    	this.options = mixin(options, defaultOptions);
    }
</script>

模块加载形式

<script>
    require(['{{module}}'], function(mixin) {
	    function A(options){
	    	this.options = mixin(options, defaultOptions);
	    }
    });
</script>

Node 模块

npm install node-mixin

文档参考

mixin mixin(des, src)

将src上的属性复制到des上

默认复制des上不存在而src上存在的属性,会忽略掉des上已经存在的属性

mixin mixin(des, src, true)

将src上的属性复制到des上并覆盖des上原有的属性

等价于 jQuery.extend(des, src)

mixin mixin(des, src, map)

依次遍历src每一个属性,对每一个属性触发一次map操作,将map的结果赋给des

如果map返回undefeind,des上的对应属性将被delete

var a = {x:{y:1, z:3}};
mixin(a, {x:{y:2}, z:2}, function(a,b){
	try{
		return mixin(a,b, arguments.callee)
	}catch(ex){
		return b
	}
});
//实现了深拷贝,等价于 jQuery.extend(true, a, {x:{y:2}, z:2});

mixin.js's People

Contributors

akira-cn 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.