我这样做了(使用版本 mootools-core-1.4.5.js)
Object.prototype.walkRecursive = function(callable, bindable) {
var p, val, retVal, _bind;
_bind = (typeof bindable === 'object') ? bindable : this;
for (p in this) {
if (this.hasOwnProperty(p)) {
if (!(this[p] instanceof Object)) {
if (typeof callable === 'function')
{
retVal = callable.call(_bind, p, this[p]);
if (typeof retVal !== 'undefined')
{
this[p] = retVal;
}
}
else {
throw "Podaj funkcje jako drugi argument";
}
} else if (this[p] instanceof Object) {
this[p].walkRecursive(callable, bindable);
}
}
}
return this;
};
然后
var navigationEl = new Element('div', {
'class' : 'wcag-navigation'
}).inject(this._element);
当我检查 this._wcagButton.pausePlay HTML 元素在 Chrome 开发者工具中的样子时,我得到了:
当我使用 Mootools 的工具时也会发生同样的事情:
Object.implement({walkRecursive :function(callable, bindable) {....}.protect()});
怎么来的?请帮忙,如何处理这个问题
使用示例
var data = [
{
id: 0,
name: 'Template 0',
subComponents: [
{id: 1, name: 'Template 1', subItems:[
{id: 2, name: 'Template 2', subComponents:[
{id: 3, name: 'Template 3'}
],
subItems: [
{id: 4, name: 'Template 4',},
{id: '42'}
]
}
]}
]}
];
var bindMe = {
nothing:'special'
}
data.walkRecursive(function(key,value){
if(key === 'name')
{
return value+' '+this.nothing;
}
},bindMe)