function dialog()
{
this.str="hello";
}
var d=new dialog();
alert(d.str);
d.str="hello2";
alert(d.str+" "+this.str+" "+dialog.str);// 结果 hello2 undefined undefined 以上str重新赋值以后 除了d.str以外还有什么方式获得str的值吗?
{
this.str="hello";
}
var d=new dialog();
alert(d.str);
d.str="hello2";
alert(d.str+" "+this.str+" "+dialog.str);// 结果 hello2 undefined undefined 以上str重新赋值以后 除了d.str以外还有什么方式获得str的值吗?
解决方案 »
- ajax,向后台发出请求,IE与火狐不一样
- 侧栏式折叠菜单NavBar 怎么和数据库绑定?
- tomcat的启动时有InvocationTargetException异常
- 谷歌的图片滚动效果是怎么实现的?
- JS能否实现或许连接的范围坐标(里面请)
- 如何在那CheckBox在选中或去掉选中的时候显示积分到HTML页面上呢?
- preventDefault()阻止被点击的链接,但不阻止这个子节点的链接,请教怎么写呢?
- 能否动态构造正则表达式
- 请问各位怎样制作新浪那样的开场拉幕效果??
- 高手请进——关于JS中调用TTS的问题
- jQuery.param这个函数反向为对象有这个方法吗
- 在线调试和演示的前端开发工具
你不是获取到str属性的内容了么?就是这种方式就可以了
非要另外的方式的话
for(var pro in d)
{
alert(pro);
}
获取一个变量的值而已,还要用几种方式,有意义么?
例子只是映射了遇到的问题
上面获得值是在已经知道实例化对象名的前提下 如果dialog()在外部js里面
然后这个.js 有一个其他的方法需要得到这个值呢
var hello=function()
{
this.str="hello";
}
hello.prototype.show=function()
{
alert(this.str)
}
var h=new hello();
h.str="hello2";
h.show();已解决 感谢x269147836 wzs_xyz
global object当中没有叫str的property,所以this.str当然是undefined
dialog是什么?global ojbect当中也没有叫dialog的property,所以也是undefined
this.str 是window.str window中没有定义str,所以是undefined
dialog.str 是类dialog的str,还没有实例化,自然取不到,所以还是undefined