Skip to content

Commit

Permalink
update array.size无法解释的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Nov 20, 2014
1 parent 206a09d commit 40f7463
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 72 deletions.
19 changes: 15 additions & 4 deletions avalon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2471,8 +2471,19 @@
var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig")
code = code.replace(reg, function(_) {
var c = _.charAt(v.length)
if (c === "." || c === "[") {
var method = /^\s*\(/.test(RegExp.rightContext)
if (c === "." || c === "[" || method) {//比如v为aa,我们只匹配aa.bb,aa[cc],不匹配aaa.xxx
var name = "var" + String(Math.random()).replace(/^0\./, "")
if (method) {//array.size()
var array = _.split(".")
if (array.length > 2) {
var last = array.pop()
assigns.push(name + " = " + array.join("."))
return name + "." + last
} else {
return _
}
}
assigns.push(name + " = " + _)
return name
} else {
Expand Down Expand Up @@ -3810,9 +3821,6 @@
for (var i in EventManager) {
array[i] = EventManager[i]
}
array.size = function() { //取得数组长度,这个函数可以同步视图,length不能
return array._.length
}
avalon.mix(array, CollectionPrototype)
return array
}
Expand Down Expand Up @@ -3852,6 +3860,9 @@
this._fire("index", n > 2 ? n - 2 : 0)
return n
},
size: function() { //取得数组长度,这个函数可以同步视图,length不能
return this._.length
},
pushArray: function(array) {
return this.push.apply(this, array)
},
Expand Down
Loading

0 comments on commit 40f7463

Please sign in to comment.