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/**--- 16 description: > 17 In a static member function,a call to 'new this()' may actually invoke a derived class constructor 18 module: ESNext 19 isCurrent: true 20 ---*/ 21 22 23import { Assert } from '../../../../../suite/assert.js' 24 25class TP { 26 constructor(public a: number = 1, public b: number = 1) { } 27 static createthis() { 28 return new this(); 29 } 30} 31class CP extends TP { 32 constructor(public a: number = 2, public b = 2) { 33 super(); 34 } 35} 36let x = TP.createthis(); 37let y = CP.createthis(); 38Assert.equal(x.a, 1); 39Assert.equal(y.a, 2);