取消订阅可观察的函数方法

时间:2018-03-10 23:46:42

标签: javascript rxjs

无法阅读财产'取消订阅'未定义的

<!doctype html>
<head>

<script>

function change() {
    var paragraph = document.getElementById("whytrust");
    paragraph.innerHTML="I am trustworthy, but how can you be sure?";
    }

</script>

</head>

<body>

<p id="whytrust" onclick="change();">You can trust me, but how can you be sure?</p>

</body>
</html>

HALP!?

commit c1a7902

1 个答案:

答案 0 :(得分:0)

在此上下文中,this是窗口对象,而不是record

function record(){
    event;
}
record.prototype = {
    start: function (){
        keyUp = Rx.Observable.fromEvent(document, "keyup");
        record.event = keyUp.subscribe((key) => {console.log(key)});
    },
    stop: function (){
        record.event.unsubscribe();
    }
}

rec = new record();
rec.start();
setTimeout(rec.stop, 2000);

https://jsfiddle.net/yn70k2g9/5/