javascript的方法可以分为三类

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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值