[英]Get the context of “this” when using the rxjs5 operator fromEvent?
How do I get the this
context when using fromEvent
observable? 使用
fromEvent
observable时如何获得this
上下文?
window.addEventListener("scroll", function(event) {
var top = this.scrollY;
console.log(top)
}, false);
But how do I get it when I do fromEvent? 但是,当我执行fromEvent时如何获得它?
Observable.fromEvent(window, 'scroll')
.subscribe((event) => {
console.log(this.scrollY);
});
the value of this inside the handler is a reference to the element.
处理程序内部的this的值是对该元素的引用。 It is the same as the value of the currentTarget property of the event argument that is passed to the handler
它与传递给处理程序的事件参数的currentTarget属性的值相同
So you could just do event.currentTarget.scrollY
. 所以你可以做
event.currentTarget.scrollY
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.