Skip to content

Commit

Permalink
修复使用Object.create引起的兼容性问题
Browse files Browse the repository at this point in the history
Fix #173
  • Loading branch information
otakustay committed Jun 2, 2016
1 parent ecfc20c commit d6c0c9d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ define(
// 如果prototype上的属性是引用类型,则复制一份,
// 防止因共享修改导致的问题
if (!this.hasOwnProperty('datasource') && this.datasource) {
this.datasource = Object.create ? Object.create(this.datasource) : u.clone(this.datasource);
this.datasource = u.clone(this.datasource);
}

if (context) {
Expand Down
8 changes: 2 additions & 6 deletions src/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ define(
var util = require('./util');
var u = require('underscore');

function create(oringin) {
return Object.create ? Object.create(oringin) : u.clone(oringin);
}

/**
* @class View
*
Expand All @@ -35,11 +31,11 @@ define(
// 如果prototype上的属性是引用类型,则复制一份,
// 防止因共享修改导致的问题
if (!this.hasOwnProperty('uiProperties') && this.uiProperties) {
this.uiProperties = create(this.uiProperties);
this.uiProperties = u.clone(this.uiProperties);
}

if (!this.hasOwnProperty('uiEvents') && this.uiEvents) {
this.uiEvents = create(this.uiEvents);
this.uiEvents = u.clone(this.uiEvents);
}

this.initialize();
Expand Down
3 changes: 2 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ define(
// 因为自己实现的`bind`很会影响调试时的单步调试,
// 跳进一个函数的时候还要经过这个`bind`几步很烦,原生的就不会
var nativeBind = Function.prototype.bind;

/**
* 固定函数的`this`变量和若干参数
*
* @param {Function} fn 操作的目标函数
* @param {Mixed} context 函数的`this`变量
* @param {Mixed...} args 固定的参数
* @param {...Mixed} args 固定的参数
* @return {Function} 固定了`this`变量和若干参数后的新函数对象
*/
util.bind = nativeBind
Expand Down

0 comments on commit d6c0c9d

Please sign in to comment.