简体   繁体   English

如何访问变量内部值的原型

[英]How to Access Prototype for value inside variable

I'm trying to access prototype for a value in variable. 我正在尝试访问原型中的变量值。
For example : 例如 :

var myObjVar = {name : 's'};
var x = "myObjVar";

Here how to access prototype of myObjVar using x ? 在这里,如何使用x访问myObjVar原型?

Its possible to access myObjVar.prototype 可以访问myObjVar.prototype

But I need to access through x ? 但是我需要通过x访问吗?

一个双重丑陋的解决方案是使用eval和非标准的__proto__属性:

eval(x).__proto__

Assuming that the object belongs to global scope: 假设对象属于全局范围:

window["myObjVar"].constructor.prototype

Otherwise use eval() (NOT RECOMMENDED!): 否则,请使用eval()(不推荐!):

eval("myObjVar").constructor.prototype

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM