Can react define a global method like vue?

for example, a function that determines whether it is an object

export const isObject = function (ob) {
  return Object.prototype.toString.call(ob)  ===  "[object Object]"
}

the function import is required for every reference, which is troublesome
but you can bind it to the prototype of the vue instance in vue, such as vue.prototype.isObject = func

.

is there a similar method for react?

Mar.10,2021

this has nothing to do with the framework. In the browser environment, directly window.XXX is fine.


    The idea of
  • react is componentization or modularization
  • should be
  • that does not support custom global variables.

Yes.
but in a different way.
higher-level components can define global methods.
or content can also provide global methods.

Menu