Make a Person(freecodecamp高级算法7)
用下面给定的方法构造一个对象.
方法有 getFirstName(), getLastName(), getFullName(), setFirstName(first), setLastName(last), and setFullName(firstAndLast).
所有有参数的方法只接受一个字符串参数.
所有的方法只与实体对象交互.
var Person = function(firstAndLast) { this.setFullName = function(name){ firstAndLast = name; } this.setFirstName = function(name){ firstAndLast = name + " " + this.getLastName(); } this.setLastName = function(name){ firstAndLast = this.getFirstName() + " " + name; } this.getFullName = function(){ return firstAndLast; } this.getFirstName = function(){ return firstAndLast.split(" ")[0]; } this.getLastName = function(){ return firstAndLast.split(" ")[1]; } }; var bob = new Person('Bob Ross'); bob.setFullName("Haskell Curry");alert(bob.getFullName());