1/* 2 * Copyright (c) 2023-2024 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// bad 17 18class C1 { 19 foo1() { 20 console.log("foo"); 21 } 22} 23 24function bar1() { 25 console.log("bar"); 26} 27 28let c11 = new C1(); 29let c12 = new C1(); 30c12.foo1 = bar; 31 32c11.foo1(); // foo 33c12.foo1(); // bar 34 35// good 36 37class C { 38 foo() { 39 console.log("foo"); 40 } 41} 42 43class Derived extends C { 44 foo() { 45 console.log("Extra"); 46 super.foo(); 47 } 48} 49 50function bar() { 51 console.log("bar"); 52} 53 54let c1 = new C(); 55let c2 = new C(); 56c1.foo(); // foo 57c2.foo(); // foo 58 59let c3 = new Derived(); 60c3.foo(); // Extra foo 61