I am working on a app that makes use of object literals to represent groups, topics, and tasks. There is also an object literal that handles command input from the app's "command-line interface".
When the user clicks on a topic, the command object sets its obj
property to refer to the object that represents what was clicked on. That is: the user clicks a group title, and now command.obj
represents the group object.
The function below resides in the command
object literal and shows how this.obj
is set. It is called when an element is clicked, that element is the obj
var passed in to the function:
/* defines taxonomy and obj of clicked element */
set_taxonomy: function(obj){
if( $(obj).hasClass('group-title') ){
this.taxonomy = $.trim('group');
this.obj = group;
}
else if($(obj).hasClass('topic-title') ){
this.taxonomy = $.trim('topic');
this.obj = topic;
}
else if( $(obj).hasClass('task') ){
this.taxonomy = $.trim('task');
this.obj = task;
}
console.log(this.obj);
this.set_commands();
},
group, topic, and title
are object literals that are loaded automatically.
When topics and titles are clicked, console.log(this.obj)
prints out object
with all the respective properties and functions.
Clicking on a group shows the number 3
.
What does the 3 mean?
See example of working topic object : http://pastebin.com/NEmKHdzc
See example of non-working group object : http://pastebin.com/ezPghLbM
Are you sure group is being set properly? Try console.log(group)
in the first if statement. If you get 3, I would double-check (with more console.log
calls) that you are setting group properly in the first place.