-
-
Save ouyangzhiping/1035211 to your computer and use it in GitHub Desktop.
HOW TO USE METHODS for CofffeeScript
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
// 理解类的方法 | |
// | |
// 第一段代码是使用默认类,定义和使用函数 | |
// 第二段代码是使用类<类Person>,定义和使用函数 | |
// | |
// 函数吃 - 函数名称 | |
// 属性修饰 - 属性名称 | |
// 属性食品 - 属性名称 | |
// 类人 - 类名称 | |
// 对象道喜 - 类的对象名称 | |
// | |
// 例如: | |
// | |
// $ node class_base_004.js | |
// => 喜欢吃苹果. | |
// => 我喜欢吃苹果. | |
// | |
var 函数吃, 对象道喜, 类人; | |
函数吃 = function(属性修饰, 属性食品) { | |
return 属性修饰 + '吃' + 属性食品 + '.'; | |
}; | |
console.log(函数吃('喜欢', '苹果')); | |
类人 = (function() { | |
function 类人() {} | |
类人.prototype.函数吃 = function(属性修饰, 属性食品) { | |
return '我' + 属性修饰 + '吃' + 属性食品 + '.'; | |
}; | |
return 类人; | |
})(); | |
对象道喜 = new 类人(''); | |
console.log(对象道喜.函数吃('喜欢', '苹果')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment