相关疑难解决方法(0)

JS中的函数调用事件?

是否可以在调用时将函数绑定到另一个函数?例如,它会像这样:

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 - …

javascript

6
推荐指数
1
解决办法
207
查看次数

使用angular2配置Hammerjs事件

如何在angular2中配置hammerjs事件?

要使用angular2的hammerjs事件,我只需要在我的html中包含事件,如下所示:

<div (press)="onLongPress($event)"></div>
Run Code Online (Sandbox Code Playgroud)

在这种情况下()默认时间为251毫秒. Hammerjs新闻事件文件

如何配置此时间以获得不同的值?

events gestures hammer.js angular

5
推荐指数
2
解决办法
1万
查看次数

在javascript中拦截函数调用

__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没有。我得到的不是函数错误。

javascript proxy function node.js

5
推荐指数
1
解决办法
3159
查看次数

检测何时在JavaScript中调用函数

HTML页面上有几个元素触发js函数HardCoded().我无法修改HardCoded()函数.

我想在调用HardCoded()函数后运行一些自定义的js代码.我怎样才能做到这一点?是否有js函数的处理程序?

我正在构建一个chrome扩展,这就是我无法修改页面源代码的原因.
我可以访问JQuery.

一种方法是找到调用HardCoded()并将事件附加到这些元素的所有元素,但我想避免使用此方法.

html javascript jquery

3
推荐指数
1
解决办法
92
查看次数

标签 统计

javascript ×3

angular ×1

events ×1

function ×1

gestures ×1

hammer.js ×1

html ×1

jquery ×1

node.js ×1

proxy ×1