<script type="text/javascript">
// 1 Function对象 , 用来定义方法.(java中的方法)
// 2 除了最后一个参数 前面的都是定义运行参数, 最后一个参数是定义运行的代码
var a ="a";
var fun1 = new Function("a","b"," document.write(a+b);");
//创建function对象的 方式2
var fun2 = function (a,b){
document.write(a+b+"</br>");//10
}
//3 第三种创建function对象的方式
function fun3(a,b){
document.write(a+b+"</br>");//12
}
fun1(1,2);
document.write("</br>");
fun2(5,5);
fun3(6,6);
</script>
三种方式
添加一个方法类元素
<script type="text/javascript">
function employee(name, job, born) {
this.name = name;
this.job = job;
this.born = born;
}
var bill = new employee("Bill Gates", "Engineer", 1985);
document.write(bill.name+">"+bill.job+">"+bill.valueOf()+">"+bill.toString());
document.write("</br>");
employee.prototype.salary = null;
document.write(bill.name+">"+bill.job+">"+bill.valueOf()+">"+bill.toString());
bill.salary = 20000;
document.write(bill);
document.write(bill.salary);
</script>