Skip to content

Instantly share code, notes, and snippets.

@LincolnBurrows
Created May 19, 2016 04:39
Show Gist options
  • Save LincolnBurrows/08d619145497858048ec67a69da1948a to your computer and use it in GitHub Desktop.
Save LincolnBurrows/08d619145497858048ec67a69da1948a to your computer and use it in GitHub Desktop.
javascript构造函数
function createObj(nick,age){
var obj = {
nick:nick,
age:age,
printName:function(){
console.log(this.nick);
}
}
return obj;
}
var obj1 = createObj('yang', 20);
obj1.printName();
///////////////////////
function cat(name){
this.name = name;
}
cat.prototype.say = function(){
console.log('hello, ' + this.name)
}
var C = new cat('yang')
C.say()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment