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的值吗?
解决方案 »
- 根据select的选择显示不同内容
- 求助:IE和FIREFOX下得的鼠标穿透事件问题
- 高分求解:如何通过代码设置jquery easyUI的menu菜单项为不可用?
- jquery ajax 获取不了 php生成的xml数据
- javascript能操作数据库吗?怎么实现?
- 帮我修改一下代码!!急
- 一个页面a 包含一个iframe页面b, c页面是b页面弹出的窗口,我想在c页面加个按钮使a页面刷新,请问这个教本怎样些
- window.API 是什么东东?
- foolfish ----->>进来接分
- JAVASCRIPT:如何将一个数字字符串(有小数点)变为数字
- 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