http://www.cnblogs.com/yjf512/archive/2011/06/03/2071914.html
a 类方法
b 对象方法
c 原型方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>
<script type="text/javascript" charset="utf-8">
// 真假对象
var checkObject = function(){
return{
checkName:function(){
alert('checkName');
},
checkEmail:function(){
alert('checkEmail')
},
checkPassord:function(){
alert('checkPassord')
}
}
}
// var a = checkObject();
// a.checkPassord()
// 类也可以
var checkObject = function(){};
checkObject.prototype = {
checkName:function(){
alert('checkName')
},
checkEmail:function(){
alert('checkEmail')
}
}
// var a = new checkObject();
// a.checkEmail();
/*// 在函数的祖先上添加方法
Function.prototype.addMethod = function(name,fn){
this[name] = fn;
return this;
}
var m = function(){};
m.addMethod('check',function(){
alert('check')
}).addMethod('check2',function(){
alert('222')
});
// m.check()*/
/*Function.prototype.add = function(name,fn){
this.prototype[name] = fn;
return this;
}
var fn = function(){};
fn.add('md',function(){
alert('md')
}).add('test',function(){
alert('test')
});
var cc = new fn();
cc.test();*/
/*
函数常见写法 以及对某个函数的扩展
*/
function people(name) {
this.name = name;
// 对象方法
this.curentFunction=function(){
console.info(this);
console.info('js中一切皆对象 这个是当前对象的方法');
}
}
// 类方法 [访问的时候通过函数名称.方法名称] people.run()
people.run = function(){
console.info(this);
console.info('采用方法名字加上函数名称就可以定义一个类方法');
}
people.rt = function(name){
alert(name)
}
/*// 如果在prototype上定义的方法就是原型方法
people.prototype.profunction = function(){
console.log('我可以访问到人们的名字:'+this.name);
};*/
people.prototype = {
checkName:function(){
alert('checkName')
},
checkEmail:function(){
alert('checkEmail')
}
}
var tes = new people('庞成勇');
// tes.curentFunction();
// people.run();
// people.rt('ppppppp');
// tes.profunction();
</script>