如何在TypeScript类中的另一个方法中调用一个方法

时间:2018-12-19 13:40:08

标签: typescript

感谢所有提供帮助的人。这个问题使我有点发疯(是的,我已经搜索过)。我收到“不是函数”错误。

我觉得这应该很容易。我只是试图从ts类从另一个方法调用一个方法。我正在尝试使用箭头功能(未显示),这对我来说有点新,但是我什么也无法工作。感谢所有帮助。

Py4JJavaError: An error occurred while calling z:org.apache.spark.h2o.JavaH2OContext.getOrCreate.
: org.apache.spark.h2o.backends.external.H2OClusterNotRunning: 
External H2O cluster is not running or could not be connected to. Provided configuration:
  cluster name            : CloudName
  cluster representative  : x.x.x.x:54321
  cluster start timeout   : 120 seconds"

It is possible that in case you provided only the cluster name, h2o is not able to cloud up
because multi-cast communication is limited in your network. In that case, please consider starting the
external H2O cluster with flatfile and set the following configuration 'spark.ext.h2o.cloud.representative'
namespace ScriptDemo
{
    export class FunctionExample
    {
        Counter: number;

        CalculateStuff(): void
        {
            this.Counter++;
            this.UpdatePage(this.Counter);
        }

        UpdatePage(counter: number): void
        {
            let label: HTMLElement = <HTMLElement>document.getElementById("output-label");
            label.innerHTML = counter.toString();
        }
    }

    window.onload = function ()
    {
        let functionExample = new FunctionExample();
        let button: HTMLButtonElement = <HTMLButtonElement>document.getElementById("UpdateCounterButton");
        button.addEventListener("click", functionExample.CalculateStuff);
    };
}

screenshot here

1 个答案:

答案 0 :(得分:0)

您的问题是这行:

0

这不是打字稿问题,如果您通过1作为回调`,在纯Javascript中也会发生同样的事情。

这会将函数@echo off timeout 1 ECHO | SET /P=sampleMailOne@gmail.com| CLIP timeout 1 ECHO | SET /P=sampleMailTwo@gmail.com| CLIP 从类中移出,并在button.addEventListener("click", functionExample.CalculateStuff); 设置为instance.CalculateStuff的情况下进行调用。使用箭头功能来确保正确保存CalculateStuff,或使用this