如何从函数中获取[[boundthis]] [英] How to get [[boundthis]] from function

查看:359
本文介绍了如何从函数中获取[[boundthis]]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的帮助。

我有2个功能:

I need your help.
I have 2 functions:

addMoveListeners: function(e) {
  e = e || window.event;
  // Binging context to function move
  moveListener = MYAPP.move.bind(e.target.parentElement);
  //
  if (e.target.classList.contains('move')){
    document.addEventListener('mousemove', moveListener, false);
    document.addEventListener('mouseup', MYAPP.removeListener, false);
  }
  resizeListener = MYAPP.resize.bind(e.target.parentElement);
  if (e.target.classList.contains('resize')){
    document.addEventListener('mousemove', resizeListener, false);
    document.addEventListener('mouseup', MYAPP.removeListener, false);
  }
  return false;
},

这个:

removeListener: function(e){
  e = e || window.event;
  //Here I want get element from function
  console.dir(resizeListener);
  // Function stores it in [[BoundThis]]
  document.removeEventListener('mousemove', resizeListener, false);
  document.removeEventListener('mouseup', MYAPP.removeListener, false);
  document.removeEventListener('mousemove', moveListener, false);
  document.removeEventListener('mouseup', MYAPP.moveListener, false);
},

如何从函数resizeListener获取属性[[BoundThis]]而不执行。

How can I get property [[BoundThis]] from function resizeListener without execution.

推荐答案

你做不到。 [[BoundThis]] 绑定的内部属性功能对象。它不能以编程方式访问。

You cannot. [[BoundThis]] is an internal property of bound function objects. It is not programmatically accessible.

您可以通过控制台检查对象来查看它,但要在程序逻辑中使用它,您需要编写自己的 bind 版本,将此值公开为属性。

You might be able to view it with inspection of the object via console, but to use it in your program logic you will need to write your own version of bind that exposes this value as a property.

这篇关于如何从函数中获取[[boundthis]]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆