Skip to content

JavaScript 类定义

musishui edited this page Feb 5, 2015 · 3 revisions
		function Apple(name) {
			var self = this instanceof Apple ? this : Object.create(Apple.prototype);
			self.name = name;
			return self;
			/*
			if (this instanceof Apple) {
				this.name = name;
			} else {
				return new Apple();
			}*/
		}

		Apple.prototype.eat = function() {
			log('Eating ' + this.name);
		};

Clone this wiki locally