题目:

用下面给定的方法构造一个对象.

方法有 getFirstName(), getLastName(), getFullName(), setFirstName(first), setLastName(last), and setFullName(firstAndLast).

所有有参数的方法只接受一个字符串参数.

所有的方法只与实体对象交互.

代码:

<script type="text/javascript">
	var Person = function(firstAndLast) {
		this.getFirstName = function() {
			return firstAndLast.split(' ')[0];
		};
		this.getLastName = function() {
			return firstAndLast.split(' ')[1];
		};
		this.getFullName = function() {
			return firstAndLast;
		};
		this.setFirstName = function(fistName) {
			var reg = new RegExp(firstAndLast.split(' ')[0], 'g');
			firstAndLast = firstAndLast.replace(reg, fistName);
		};
		this.setLastName = function(lastName) {
			var reg = new RegExp(firstAndLast.split(' ')[1], 'g');
			firstAndLast = firstAndLast.replace(reg, lastName);
		};
		this.setFullName = function(fullName) {
			firstAndLast = fullName;
		};

	};
</script>