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 16declare function print(arg:any):string; 17function Dog(name) { 18 this.name = name; 19} 20 21const dog1 = new Dog('Gabby'); 22 23Dog.prototype.toString = function dogToString() { 24 return `${this.name}`; 25}; 26 27print(dog1.toString()); 28print(Object.prototype.toString.call(dog1)); 29 30let o = new Object(); 31print(o.toString()) 32 33let n = new Number(1); 34print(Object.prototype.toString.call(n)); 35 36let s = "ss"; 37print(Object.prototype.toString.call(s)); 38print(s.toString()); 39 40print(Object.prototype.toString.call(new Date())); 41print(Object.prototype.toString.call(new String())); 42// Math has its Symbol.toStringTag 43print(Object.prototype.toString.call(Math)); 44 45 46print(Object.prototype.toString.call(null)); 47print(Object.prototype.toString.call()); 48 49const myDate = new Date(); 50print(Object.prototype.toString.call(myDate)); 51 52myDate[Symbol.toStringTag] = "myDate"; 53print(Object.prototype.toString.call(myDate)); 54 55Date.prototype[Symbol.toStringTag] = "prototype polluted"; 56print(Object.prototype.toString.call(new Date())); 57