There are many issues with your code and you should lint it to view your syntax errors.
Also, you probably want to read more about Object Oriented JavaScript.
However, here's what you are trying to achieve (I think):
DEMO: http://jsfiddle.net/FR8B8/
function Person(address) {
this.setAddress(address);
}
Person.prototype = {
setAddress: function (address) {
this.address = address;
},
getAddress: function () {
return this.address;
}
};
function Address(fullAddress) {
this.setFullAddress(fullAddress);
}
Address.prototype = {
setFullAddress: function (fullAddress) {
//naive parsing
var addressParts = fullAddress.match(/(.+),(.+),(.+),(.+)/);
this.fullAddress = fullAddress;
this.address = addressParts[1];
this.city = addressParts[2];
this.state = addressParts[3];
this.zip = addressParts[4];
},
getFullAddress: function () {
return this.fullAddress;
}
};
var a = new Address('15 test,Test City,Test State,J9A333'),
p = new Person(a);
console.log(p.getAddress());
I am trying to assign the fullAddress from Address object to the
Person object address. Am i referencing getFullAddress correctly in
setPersonAddress?
That could be done easily, however since you already have an Address value object it's probably better that the Person object encapsulates an instance of an Address object instead of a string.
From the example below, you can get the full address of a person by doing p.getAddress().getFullAddress(). Note that could create a getFullAddress function member on the Person object that encapsulate this logic to simplify things.
this.setPersonAddress = function (a.getFullAddress()) {< this makes no sense, you probably wantthis.setPersonAddress = function (a) {(var address = setPersonAddress();this too, makes no sense ;))