题目:
用下面给定的方法构造一个对象.
方法有 getFirstName), getLastName), getFullName), setFirstNamefirst), setLastNamelast), and setFullNamefirstAndLast).
所有有参数的方法只接受一个字符串参数.
所有的方法只与实体对象交互.
代码:
<script type="text/javascript">
var Person = functionfirstAndLast) {
this.getFirstName = function) {
return firstAndLast.split' ')[0];
};
this.getLastName = function) {
return firstAndLast.split' ')[1];
};
this.getFullName = function) {
return firstAndLast;
};
this.setFirstName = functionfistName) {
var reg = new RegExpfirstAndLast.split' ')[0], 'g');
firstAndLast = firstAndLast.replacereg, fistName);
};
this.setLastName = functionlastName) {
var reg = new RegExpfirstAndLast.split' ')[1], 'g');
firstAndLast = firstAndLast.replacereg, lastName);
};
this.setFullName = functionfullName) {
firstAndLast = fullName;
};
};
</script>