Home > Web Front-end > JS Tutorial > body text

JavaScript AOP implements ajax callback function which is more convenient to use_javascript skills

WBOY
Release: 2016-05-16 18:15:50
Original
1121 people have browsed it
复制代码 代码如下:

function actsAsDecorator(object) {
object.setupDecoratorFor = function(method) {
if (! ('original_' method in object) ) {
object['original_' method] = object[method];
object['before_' method] = [ ];
object['after_' method] = [ ];
object[method] = function() {
var i;
var b = this['before_' method];
var a = this['after_' method];
var rv;
for (i = 0; i < b.length; i ) {
b[i].call(this, arguments);
}
rv = this['original_' method].apply(this, arguments);
for (i = 0; i < a.length; i ) {
a[i].call(this, arguments);
}
return rv;
}
}
};
object.before = function(method, f) {
object.setupDecoratorFor(method);
object['before_' method].unshift(f);
};
object.after = function(method, f) {
object.setupDecoratorFor(method);
object['after_' method].push(f);
};
}
/**
Invoking
*/
function Test(){
this.say1 = function(s){
alert(s);
}
this.say2 = function(s){
alert(s);
}
}
var t = new Test();
actsAsDecorator(t);
t.before("say1",beforeHander);
t.after("say2",afterHander);
test();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!