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
我后面的car.prototype.show=function (){
alert("hello world");
}
不可以把前面的方法覆盖掉么,
{{
相关问答:
如何实现当鼠标悬停控件上时,出现该控件的尾部显示对应的层,鼠标移动到该层上进行相应的操作,当鼠标移除时(不在控件上也不在层上)层隐藏,
http://topic.csdn.net/u/20090830/23/5e5ded07-7216-46c2-9712- ......
用javascript加载页面时指向一个描点。已知如何通过链接做成描点的,可是想让页面加载时直接指向不需要点击链接。
1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ......
我的源文件如下:
<html>
<head> <title>show picture </title>
<script>
function change(fileName)
{
  ......
我也来一个趣味javascript:
打开以下html文件,依次按下G,L,C三个键,就会有奇迹出现!!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" ......
以下是一段JavsScript脚本,但运行时总会产生 “Microsoft JScript 运行时错误: 'null' 为空或不是对象”异常,大家帮看一下。
<form id="form1" runat="server">
< ......