1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15/**--- 16description: > 17 this parameters in callbacks.Libraries can also use this parameters to declare how callbacks will be invoked. 18 this: void means that addClickListener expects onclick to be a function that does not require a this type. 19module: ESNext 20isCurrent: true 21---*/ 22 23 24import { Assert } from "../../../suite/assert.js" 25 26interface Web { 27 Click(onclick: (this: void, e: Event) => void): void; 28} 29 30class NetLink { 31 info: string; 32 constructor(info: string) { 33 this.info = info; 34 } 35 onClickGood(this: void, e: Event) { 36 } 37} 38 39let web: Web = { 40 Click(Onclick: (this: void, e: Event) => void) { 41 Assert.equal(typeof this, "object"); 42 } 43}; 44let onAir = new NetLink("OnAir"); 45web.Click(onAir.onClickGood);