易截截图软件、单文件、免安装、纯绿色、仅160KB

JavaScript的重定义方法的问题

function car(sColor){
this.color=sColor;
if(typeof car._initialized =="undefined"){
car.prototype.show=function(){
alert(this.color);
}
}
}

car.prototype.show=function (){
alert("hello world");
}

var s=new car();
s.show();
为什么不输出hello world,而输出undefined

var s=new car("red");

你每次new car()的时候,car()里的代码都会运行一次
而在car()里因为typeof car._initialized =="undefined"成立,所以每当new car()的时候,car.prototype.show都会被修改成为
function(){
alert(this.color);
}
而你的new car()中没有参数,所以得到undefined

引用
你每次new car()的时候,car()里的代码都会运行一次
而在car()里因为typeof car._initialized =="undefined"成立,所以每当new car()的时候,car.prototype.show都会被修改成为
function(){
alert(this.color);
}
而你的new car()中没有参数,所以得到undefined

我后面的car.prototype.show=function (){
alert("hello world");
}
不可以把前面的方法覆盖掉么,
{{


相关问答:

javaScript 悬停浮动层定位

如何实现当鼠标悬停控件上时,出现该控件的尾部显示对应的层,鼠标移动到该层上进行相应的操作,当鼠标移除时(不在控件上也不在层上)层隐藏,

http://topic.csdn.net/u/20090830/23/5e5ded07-7216-46c2-9712- ......

Javascript描点问题 - Web 开发 / JavaScript

用javascript加载页面时指向一个描点。已知如何通过链接做成描点的,可是想让页面加载时直接指向不需要点击链接。
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ......

如何用javascript在页面中动态更新某一块的内容?

我的源文件如下:
<html>
<head> <title>show picture </title>
<script>
function change(fileName)
    {
     
    ......

趣味javascript... - Web 开发 / JavaScript

我也来一个趣味javascript:
打开以下html文件,依次按下G,L,C三个键,就会有奇迹出现!!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" ......

这段JavaScript代码为什么无法执行 - .NET技术 / C#

以下是一段JavsScript脚本,但运行时总会产生 “Microsoft JScript 运行时错误: 'null' 为空或不是对象”异常,大家帮看一下。 
<form id="form1" runat="server">
  < ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号