首页 > 解决方案 > 如何挂钩新 String 实例的每次创建?

问题描述

是否可以挂钩每个新的创建String?每次运行这样的代码:

const new_string = 'Hello World!';

我想收到通知;例如;

console.log('A new String was created:', whatever_new_string_was_created);

标签: javascriptstringdebugginghook

解决方案


字符串是没有关联事件的原语,构造函数无法更改其方法:https ://tc39.es/ecma262/#sec-string-objects


推荐阅读