Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
818 views
in Technique[技术] by (71.8m points)

javascript - How to get [[boundthis]] from function

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;
},

and this:

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);
},

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...