是否可以在调用时将函数绑定到另一个函数?例如,它会像这样:
function a(){...}
function b(){...}
b.bind("onInvoke","a");
Run Code Online (Sandbox Code Playgroud)
因此,当调用b时,也会自动调用a.
编辑:好的,澄清一下,这不是关于链接的问题.我们的想法是找到一种优雅的方式来进行事件绑定.通过正常的函数回调观察正常的"非优雅"方式:
function handler(){...}
function caller1(){handler(); ...}
function caller2(){handler(); ...}
function caller2(){handler(); ...}
// More callers all over your website everywhere else
Run Code Online (Sandbox Code Playgroud)
那可行吗?但是,如果我到处都有来电者怎么办?组织或改变事物很难.
现在观察优越的解决方案!(如果存在的话)
function handler(){...}
// Caller make no reference to handler on creation
function caller1(){...}
function caller2(){...}
function caller3(){...}
// Caller function are still all over the place, all over your website
// Event handler registered later in one location here, doesn't matter where they are phsically
caller1.bind("onInvoke",handler);
caller2.bind("onInvoke",handler);
caller3.bind("onInvoke",handler);
Run Code Online (Sandbox Code Playgroud)
所以非常像你的普通HTML - …
如何在angular2中配置hammerjs事件?
要使用angular2的hammerjs事件,我只需要在我的html中包含事件,如下所示:
<div (press)="onLongPress($event)"></div>
Run Code Online (Sandbox Code Playgroud)
在这种情况下(按)默认时间为251毫秒. Hammerjs新闻事件文件
如何配置此时间以获得不同的值?
__callPHP中的魔法方法的等价物是什么?
我的印象是 Proxy 可以做到这一点,但它不能。
class MyClass{
constructor(){
return new Proxy(this, {
apply: function(target, thisArg, args){
console.log('call', thisArg, args);
return 'test';
},
get: function(target, prop){
console.log('get', prop, arguments);
}
});
}
}
var inst = new MyClass();
console.log(inst.foo(123));
Run Code Online (Sandbox Code Playgroud)
get似乎有效,因为我看到“get foo”,但apply没有。我得到的不是函数错误。
HTML页面上有几个元素触发js函数HardCoded().我无法修改HardCoded()函数.
我想在调用HardCoded()函数后运行一些自定义的js代码.我怎样才能做到这一点?是否有js函数的处理程序?
我正在构建一个chrome扩展,这就是我无法修改页面源代码的原因.
我可以访问JQuery.
一种方法是找到调用HardCoded()并将事件附加到这些元素的所有元素,但我想避免使用此方法.