日期:2014-05-16  浏览次数:20415 次

JavaScript 对象专题
JavaScript 对象
JS Array
JS Boolean
JS Date
JS Math
JS Number
JS String
JS RegExp
JS Functions
JS Events

http://www.w3school.com.cn/js/js_reference.asp

prototype 属性使您有能力向对象添加属性和方法。

语法
object.prototype.name=value

<script type="text/javascript">

String.prototype.trim = function() {   
     return this.replace(/^[\s\u3000\xA0]+|[\s\u3000\xA0]+$/g,"");     
}  

function Employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}

var bill=new Employee("  Bill Gates","Engineer",1985);

Employee.prototype.salary=null;
bill.salary=20000;

document.write(bill.salary);
document.write(bill.name.trim());

-- 结果2000Bill Gates

</script>