我做了很多如下所示的函数
function a(declara,callback) {
x = declara.x;
y = declara.y;
return callback.call(this,[declara]);
}
a({x:1,y:2},function(){ console.log(x+" , "+y); });
但是我发现回调实际上不起作用,请您解释一下,如何实现管道结构如下:
a({x:1,y:2}).print()
(类似于jQuery的功能,请同样解释一下!)
最佳答案
如果我正确理解了您的问题,那么
function a(declara) {
x = declara.x;
y = declara.y;
return {print:function(){ console.log(x+" , "+y); }}; //return an object whose one key-value has function inside of it.
}
a({x:1,y:2}).print();