Basic question about jQuery OOP
I just decided to use OOP in a project I'm working on. And I had a basic question about reaching properties in the root of the prototype from functions that lie within objects.
Heres the jQuery:
- var Person = function(first, last){
- this._first = first;
- this._last = last;
- };
-
- Person.prototype = {
- full: function(){
- return this._first +' '+this._last;
- },
- first: function( ){
- return this._first;
- },
- last: function(){
- return this._last;
- },
- hobbies: {
- computers: {
- init: function(){
- console.debug(this._first +' '+this._last + ' likes Computers');
- }
- },
- cars: {
- init: function(){
- console.debug(this._first +' '+this._last + ' likes Cars');
- }
- }
- }
- };
-
- var p1 = new Person('John','Doe');
- p1.hobbies.computers.init();
-
- var p2 = new Person('Jack','Black');
- p2.hobbies.cars.init();
Basically, if I wanted to call elements deeper within the object than just the first level, how can I reach properties stored in the root? Those console outputs should say "John Doe likes Computers" and "Jack Black likes Cars". Ive been reading a few jQuery OOP Articles, mainly
this one and
this one.
Thanks!