Created
May 19, 2016 04:39
-
-
Save LincolnBurrows/08d619145497858048ec67a69da1948a to your computer and use it in GitHub Desktop.
javascript构造函数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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