javascript Js - 面向对象编程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Js - 面向对象编程相关的知识,希望对你有一定的参考价值。

function Person(fullName, favColor) {
	this.name = fullName;
	this.favoriteColor = favColor;
	this.greet = function (){
		console.log('Hello, my name is '+ this.name + ' and my favorite color is ' + this.favoriteColor '.');
	}
}

var john = new Person('John Doe', 'blue');
john.greet();

var jane = new Person('Jane Smith', 'green');
jane.greet();

以上是关于javascript Js - 面向对象编程的主要内容,如果未能解决你的问题,请参考以下文章