码迷,mamicode.com
首页 > Web开发 > 详细

js面向对象写法

时间:2017-07-22 16:49:38      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:prototype   ons   this   rip   on()   面向   prot   init   pre   

//对象字面量写法
var fn = {
    name: ‘hello world‘,
    fn1: function() {
        console.log(this.name);
    }
};
fn.fn1();
//prototype原型写法
function Fn() {
    this.name = ‘hello world‘;
    this.fn1 = function() {
        console.log(this.name);
    };
    Fn.prototype.fn2 = function() {
        console.log(this.name);
    };
}
Fn.prototype.fn3 = function() {
   console.log(this.name);
};
Fn.prototype.init = function() {
    fn.fn1();
    fn.fn2();
    fn.fn3();
};
var fn = new Fn();
fn.init();

  

js面向对象写法

标签:prototype   ons   this   rip   on()   面向   prot   init   pre   

原文地址:http://www.cnblogs.com/huangtonghui/p/7221435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!