Node 基础

Node 创建对象的方法

1.

var  User = new Object();

User.first = "Brad";

User.second = "Balyley";

User.getName = function(){ return this.first + " " + this.second;}

2. 

var User = {

  first:'Brad',

  second:'Balyley',

  getName:function(){return this.first + " " + this.second}

3.

function User(first,second){

  this.first = first;

  this.second = second;

  this.getName = function(){this.first + " " + this.second;}

}

4.

funciton User(first,second)

{  

  this.first = first;

  this.second = second;

}

User.prototype = {

  getName:function(){

    return this.first + " " + this.second;

}

}

猜你喜欢

转载自www.cnblogs.com/ninjakim/p/9218418.html