Created
July 5, 2014 13:50
-
-
Save hjzheng/b5758c37b70b9acba093 to your computer and use it in GitHub Desktop.
JavaScript继承(原型继承)
This file contains hidden or 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
//JavaScript 原型继承 | |
function extend(obj){ | |
var F = function(){}; | |
F.prototype = obj; | |
return new F(); | |
} | |
var obj = { | |
name: "xxxx" | |
}; | |
var sub = extend(obj); | |
console.log(sub.name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment