库和API的设计:
使用//var x === undefined ? 0 : x;
function extend(target, source) {
if(source) {
for(var key in source) {
var val = source[key];
if(typeof val !== ‘undefined‘) {
target[key] = val;
}
}
}
return target;
}
function Alert(parent, opts) {
opts = extend({
width: 320,
height: 240
}, opts);
opts = extend({
x: (parent.width/2) - (opts.width),
y: (parent.height/2) - (opts.height),
title: ‘Alert‘,
icon: ‘info‘,
modal: false
}, opts);
extend(this, opts);
}
var alert = new Alert({width:1200,height:1000},{title:‘child‘,modal:‘true‘});
原文:http://www.cnblogs.com/jinkspeng/p/4151009.html