如何在Javascript中找到属性的所有者 [英] How to find the owner of a property in Javascript
问题描述
好的,因为我最初的问题听起来不太清楚,所以我决定编辑它。我的问题是你如何找出谁定义了某个属性,例如 parseInt
函数,我如何知道它被定义的对象,如果 parseInt
在窗口
对象或文档
对象或其他任何对象上定义是什么?谢谢
Ok, because my initial question sounds unclear, so I decided to edit it. My question is how do you find out who defined a certain property, for example, the parseInt
function, how do I know on which object it was definded like if parseInt
was definded on the window
object or the document
object or whatever object it is? Thank you
我知道 parseInt
被定义为窗口
对象,我一般只是用它作为一个例子,我没有具体询问什么对象定义 parseInt
属性。
I know the parseInt
was definded the window
object, I am just using it as an example in general, I am not specifically asking what object definded the parseInt
property.
另外,请不要告诉我jQuery代码,因为我不知道jQuery非常好。
Also, please don't show me jQuery codes since I don't know jQuery that very good.
推荐答案
遗憾的是,没有办法确定使用代码变量环境是给定变量的。
There is unfortunately no way to determine using code what the variable environment is of a given variable.
对于对象属性,如果它们是 myObj.property
,它们应该是显而易见的。如果不是很明显,可以使用详尽的搜索来查找它们在某些地方的存在,或者某些已知的递归。
As for object properties, they should be obvious if they are myObj.property
. If not obvious, it could be possible to use an exhaustive search to look for their existence in certain places, or certain known recursively.
总的来说,不可能知道没有查看实施文档。
Overall, it is not possible to know without looking at implementation documentation.
这篇关于如何在Javascript中找到属性的所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!