首页 > 解决方案 > 无法在 Next.js 中声明 Object.prototype

问题描述

我正在尝试为 Next.js 中的对象创建自定义函数

我正在写以下内容

Object.prototype._something = function (something) {
   console.log(something)
}

它有效,但现在它给了我一个奇怪的错误

Warning: Invalid value for prop `_something` on <img> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM.

但它只适用于 Object.prototype,如果我声明与 Array.prototype 相同的函数,一切正常

标签: javascriptreactjsnext.js

解决方案


推荐阅读