Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

给set方法的option增加override配置,满足强制覆盖对象类型的需求 #13

Merged
merged 1 commit into from
Mar 29, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ define(function(require, exports) {

options || (options = {});
var silent = options.silent;
var override = options.override;

var now = this.attrs;
var changed = this.__changedAttrs || (this.__changedAttrs = {});
Expand All @@ -95,8 +96,9 @@ define(function(require, exports) {
var prev = this.get(key);

// 获取需要设置的 val 值
// 如果设置了 override 为 true,表示要强制覆盖,就不去 merge 了
// 都为对象时,做 merge 操作,以保留 prev 上没有覆盖的值
if (isPlainObject(prev) && isPlainObject(val)) {
if (!override && isPlainObject(prev) && isPlainObject(val)) {
val = merge(merge({}, prev), val);
}

Expand Down