JavaScript prototype 属性
定义与用法
The prototype property allows you to add properties and methods to an
object.
prototype属性允许你向一个对象添加属性和方法
Syntax
语法
object.prototype.name=value
Example 1
实例
In this example we will show how to use the prototype property to add a
property to an object:
在下面的例子中,我们将演示如何用prototype属性来向一个对象增加一个属性:
<script type="text/javascript">
function employee(name,jobtitle,born)
{
this.name=name
this.jobtitle=jobtitle
this.born=born
}
var fred=new employee("Fred Flintstone","Caveman",1970)
employee.prototype.salary=null
fred.salary=20000
document.write(fred.salary)
</script>
The output of the code above will be:
输出结果为:
20000
相关文档:
对于JavaScript的 Stack overflow at line 错误总结
该错误只在IE中出现,出现该提示的原因主要有两种:
1. 重定义了系统的触发事件名称作为自定义函数名如: onclick / onsubmit ... 都是系统保留的事件名称,不允许作为重定义函数名称。
2. ......
var obj = new Object();
obj.name = "hello";
obj['name'] = "world";
alert(obj.name);
被人问到这样一段代码,alert的结果应该是什么呢?
我回答:hello #结果大错特错!
应该是“world”!!!
因为js是一种松散类型的语言,obj虽然被声明是一个对象,但是把它当成数组来访问也没什么不可以。
虽然 ......
AA.HTM
-------------------------------------
<!--
showModalDialog函数的使用 (转)
本范例可以实现弹出一个模态窗口,并演示了两种接收和传递参数的方法,同时可以接受模态窗口返回的多个变量
-->
<html> &nbs ......
JS自带函数
concat
将两个或多个字符的文本组合起来,返回一个新的字符串。
var a = "hello";
var b = ",world";
var c = a.concat(b);
alert(c);
//c = "hello,world"
indexOf
返回字符串中一个子串第一处出现的索引(从左到右搜索)。如果没有匹配项,返回 -1 。
var index1 = a.indexOf("l");
//index1 = 2 ......