Skip to content

Instantly share code, notes, and snippets.

@ouyangzhiping
Forked from cnruby/class_base_004.js
Created June 20, 2011 06:34
Show Gist options
  • Save ouyangzhiping/1035211 to your computer and use it in GitHub Desktop.
Save ouyangzhiping/1035211 to your computer and use it in GitHub Desktop.
HOW TO USE METHODS for CofffeeScript
// 理解类的方法
//
// 第一段代码是使用默认类,定义和使用函数
// 第二段代码是使用类<类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