|
|
|
@ -11,47 +11,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
|
|
return typeof Ctor === 'function' && /native code/.test(Ctor.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var rhashcode = /\d\.\d{4}/; |
|
|
|
|
|
|
|
|
|
//生成UUID http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
|
|
|
|
|
function makeHashCode(prefix) { |
|
|
|
|
/* istanbul ignore next*/ |
|
|
|
|
prefix = prefix || 'bi'; |
|
|
|
|
/* istanbul ignore next*/ |
|
|
|
|
return String(Math.random() + Math.random()).replace(rhashcode, prefix); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var hasProto = '__proto__' in {}; |
|
|
|
|
|
|
|
|
|
var isIE = function isIE() { |
|
|
|
|
if (typeof navigator === "undefined") { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return (/(msie|trident)/i.test(navigator.userAgent.toLowerCase()) |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var getIEVersion = function getIEVersion() { |
|
|
|
|
var version = 0; |
|
|
|
|
if (typeof navigator === "undefined") { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
var agent = navigator.userAgent.toLowerCase(); |
|
|
|
|
var v1 = agent.match(/(?:msie\s([\w.]+))/); |
|
|
|
|
var v2 = agent.match(/(?:trident.*rv:([\w.]+))/); |
|
|
|
|
if (v1 && v2 && v1[1] && v2[1]) { |
|
|
|
|
version = Math.max(v1[1] * 1, v2[1] * 1); |
|
|
|
|
} else if (v1 && v1[1]) { |
|
|
|
|
version = v1[1] * 1; |
|
|
|
|
} else if (v2 && v2[1]) { |
|
|
|
|
version = v2[1] * 1; |
|
|
|
|
} else { |
|
|
|
|
version = 0; |
|
|
|
|
} |
|
|
|
|
return version; |
|
|
|
|
}; |
|
|
|
|
var isIE9Below = isIE() && getIEVersion() < 9; |
|
|
|
|
|
|
|
|
|
var _toString = Object.prototype.toString; |
|
|
|
|
|
|
|
|
|
function isPlainObject(obj) { |
|
|
|
@ -266,7 +227,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
|
|
var createViewModel = Object.defineProperties; |
|
|
|
|
var defineProperty = void 0; |
|
|
|
|
|
|
|
|
|
var timeBucket = new Date() - 0; |
|
|
|
|
/* istanbul ignore if*/ |
|
|
|
|
if (!canHideProperty) { |
|
|
|
|
if ('__defineGetter__' in {}) { |
|
|
|
@ -291,76 +251,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
|
|
return obj; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
/* istanbul ignore if*/ |
|
|
|
|
if (isIE9Below) { |
|
|
|
|
var VBClassPool = {}; |
|
|
|
|
window.execScript([// jshint ignore:line
|
|
|
|
|
'Function parseVB(code)', '\tExecuteGlobal(code)', 'End Function' //转换一段文本为VB代码
|
|
|
|
|
].join('\n'), 'VBScript'); |
|
|
|
|
|
|
|
|
|
var VBMediator = function VBMediator(instance, accessors, name, value) { |
|
|
|
|
// jshint ignore:line
|
|
|
|
|
var accessor = accessors[name]; |
|
|
|
|
if (arguments.length === 4) { |
|
|
|
|
accessor.set.call(instance, value); |
|
|
|
|
} else { |
|
|
|
|
return accessor.get.call(instance); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
createViewModel = function createViewModel(name, accessors, properties) { |
|
|
|
|
// jshint ignore:line
|
|
|
|
|
var buffer = []; |
|
|
|
|
buffer.push('\tPrivate [$vbsetter]', '\tPublic [$accessors]', '\tPublic Default Function [$vbthis](ac' + timeBucket + ', s' + timeBucket + ')', '\t\tSet [$accessors] = ac' + timeBucket + ': set [$vbsetter] = s' + timeBucket, '\t\tSet [$vbthis] = Me', //链式调用
|
|
|
|
|
'\tEnd Function'); |
|
|
|
|
//添加普通属性,因为VBScript对象不能像JS那样随意增删属性,必须在这里预先定义好
|
|
|
|
|
var uniq = { |
|
|
|
|
$vbthis: true, |
|
|
|
|
$vbsetter: true, |
|
|
|
|
$accessors: true |
|
|
|
|
}; |
|
|
|
|
for (name in $$skipArray) { |
|
|
|
|
if (!uniq[name]) { |
|
|
|
|
buffer.push('\tPublic [' + name + ']'); |
|
|
|
|
uniq[name] = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//添加访问器属性
|
|
|
|
|
for (name in accessors) { |
|
|
|
|
if (uniq[name]) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
uniq[name] = true; |
|
|
|
|
buffer.push( |
|
|
|
|
//由于不知对方会传入什么,因此set, let都用上
|
|
|
|
|
'\tPublic Property Let [' + name + '](val' + timeBucket + ')', //setter
|
|
|
|
|
'\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Set [' + name + '](val' + timeBucket + ')', //setter
|
|
|
|
|
'\t\tCall [$vbsetter](Me, [$accessors], "' + name + '", val' + timeBucket + ')', '\tEnd Property', '\tPublic Property Get [' + name + ']', //getter
|
|
|
|
|
'\tOn Error Resume Next', //必须优先使用set语句,否则它会误将数组当字符串返回
|
|
|
|
|
'\t\tSet[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tIf Err.Number <> 0 Then', '\t\t[' + name + '] = [$vbsetter](Me, [$accessors],"' + name + '")', '\tEnd If', '\tOn Error Goto 0', '\tEnd Property'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (name in properties) { |
|
|
|
|
if (!uniq[name]) { |
|
|
|
|
uniq[name] = true; |
|
|
|
|
buffer.push('\tPublic [' + name + ']'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
buffer.push('\tPublic [hasOwnProperty]'); |
|
|
|
|
buffer.push('End Class'); |
|
|
|
|
var body = buffer.join('\r\n'); |
|
|
|
|
var className = VBClassPool[body]; |
|
|
|
|
if (!className) { |
|
|
|
|
className = makeHashCode('VBClass'); |
|
|
|
|
window.parseVB('Class ' + className + body); |
|
|
|
|
window.parseVB(['Function ' + className + 'Factory(acc, vbm)', //创建实例并传入两个关键的参数
|
|
|
|
|
'\tDim o', '\tSet o = (New ' + className + ')(acc, vbm)', '\tSet ' + className + 'Factory = o', 'End Function'].join('\r\n')); |
|
|
|
|
VBClassPool[body] = className; |
|
|
|
|
} |
|
|
|
|
var ret = window[className + 'Factory'](accessors, VBMediator); //得到其产品
|
|
|
|
|
return ret; //得到其产品
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var createViewModel$1 = createViewModel; |
|
|
|
@ -700,11 +590,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
|
|
} else { |
|
|
|
|
this.model = this.walk(value); |
|
|
|
|
} |
|
|
|
|
if (isIE9Below) { |
|
|
|
|
this.model['__ob__'] = this; |
|
|
|
|
} else { |
|
|
|
|
def(this.model, "__ob__", this); |
|
|
|
|
} |
|
|
|
|
def(this.model, "__ob__", this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Observer.prototype.walk = function walk(obj) { |
|
|
|
|