Skip to content

Commit d9089bd

Browse files
committed
Released on 20171104.
1 parent 2cf2283 commit d9089bd

File tree

4 files changed

+83
-15
lines changed

4 files changed

+83
-15
lines changed

dist/mvvm.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
2-
* mvvm.js v1.4.0 (c) 2017 TANG
2+
* mvvm.js v1.4.1 (c) 2017 TANG
33
* Released under the MIT license
4-
* Sat Oct 14 2017 08:39:43 GMT+0800 (CST)
4+
* Sat Nov 04 2017 11:30:28 GMT+0800 (CST)
55
*/
66
(function (global, factory) {
77
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -1258,6 +1258,20 @@
12581258
var regQuotes = /(^'*)|('*$)|(^"*)|("*$)/g
12591259
var regJsonFormat = /[^,]+:[^:]+((?=,[^:]+:)|$)/g
12601260

1261+
/**
1262+
* 生成匿名事件函数
1263+
* @param {String} expression
1264+
* @return {Function}
1265+
*/
1266+
function createAnonymous (expression) {
1267+
try {
1268+
return new Function('scope', addScope(expression))
1269+
} catch (e) {
1270+
error('Invalid generated expression: [' + expression + ']')
1271+
return noop
1272+
}
1273+
}
1274+
12611275
/**
12621276
* 分解字符串函数参数
12631277
* @param {String} funcString
@@ -1326,6 +1340,11 @@
13261340
var info = stringToParams(expression)
13271341
var func = info.func, args = info.args
13281342

1343+
// 尝试匿名函数表达式
1344+
if (!isNormal(func)) {
1345+
func = createAnonymous(expression)
1346+
}
1347+
13291348
return { type: type, dress: dress, func: func, args: args }
13301349
}
13311350

@@ -1340,7 +1359,7 @@
13401359
var expression = desc.expression
13411360

13421361
if (args) {
1343-
binds.push(formatEvent(args, expression))
1362+
binds = [formatEvent(args, expression)]
13441363
} else {
13451364
var json = convertJson(expression)
13461365
each(json, function (value, key) {
@@ -1432,6 +1451,10 @@
14321451
var dress = bind.dress
14331452
var capture = dress.indexOf('capture') > -1
14341453

1454+
if (isFunc(func)) {
1455+
return this.bindAnonymousEvent(type, dress, func)
1456+
}
1457+
14351458
if (func === '$remove') {
14361459
return this.bindRemoveEvent(type, dress)
14371460
}
@@ -1459,7 +1482,18 @@
14591482
}
14601483

14611484
/**
1462-
* 隐性绑定删除($remove) vfor 选项事件
1485+
* 绑定匿名事件
1486+
* @param {String} type [事件类型]
1487+
* @param {String} dress [事件修饰符]
1488+
* @param {Function} func [匿名事件函数]
1489+
*/
1490+
von.bindAnonymousEvent = function (type, dress, func) {
1491+
var scope = this.scope || this.vm.$data
1492+
this.bindEvent(type, dress, func.bind(scope, scope))
1493+
}
1494+
1495+
/**
1496+
* 匿名绑定删除($remove) vfor 选项事件
14631497
* @param {String} type [事件类型]
14641498
* @param {String} dress [事件修饰符]
14651499
*/

0 commit comments

Comments
 (0)