js class初级运用

1.直接运用对象

var myClass = {
      uname : 'sgw',
      getName : function(){
        return this;
      }
    }
console.log(myClass.getName());

2.new 创建对象

var Car = function(name,num){
      var carName = name;
      var carNum = num;

      var _this = this;

      _this.getName = function(){
        getCarName();
        getCarNum();
      }

      getCarNum = function (){
        console.log(carNum);
      }
      function getCarName(){
        console.log(carName);
      }
    }

    var myCar = new Car('dd','3');
    myCar.getName();

 

posted @ 2015-05-06 17:43  雷林007  阅读(175)  评论(0编辑  收藏  举报