max7
asked on
What does this mean in jQuery?
Greetings,
Check out the code included below. While I want to gain a general understanding what it's doing (have a basic idea but want to reinforce my understanding), I especially want to know what the following construct means:
if (CreateProfile.oComments!= null)
in particular I want to under what the 'o' in '.oComments' means i.e. what its purpose is since I see this construct throughout the coding in other places.
Keep in mind my knowledge base is very minimal for this type of thing so don't be surprised if in a reply I say something that shows my ignorance of the topic, thanks.
Check out the code included below. While I want to gain a general understanding what it's doing (have a basic idea but want to reinforce my understanding), I especially want to know what the following construct means:
if (CreateProfile.oComments!=
in particular I want to under what the 'o' in '.oComments' means i.e. what its purpose is since I see this construct throughout the coding in other places.
Keep in mind my knowledge base is very minimal for this type of thing so don't be surprised if in a reply I say something that shows my ignorance of the topic, thanks.
commentsUser:function(){
var data =
$.ajax({
type:"POST",
url: DSMWSDOMAIN_URL + 'contestants/get-comments/',
data: 'contestant_id='+Global.DSMUser[0].contestant_id+'&campaign_id=' +Global.DSMId,
dataType: 'json',
async: false
});
if (!DSM.empty(data.responseText))
{
CreateProfile.oComments=JSON.parse(data.responseText);;
}
if (CreateProfile.oComments!=null){
var strongComment=$('#usercomment');
strongComment.html(CreateProfile.oComments[0].display_name.substring(0,30));
var divComment=$('#infocomment');
divComment.html(CreateProfile.oComments[0].comment);
if (CreateProfile.oComments.length>1){
$('.view_more_comments').css('display','block');
$('#totcomments').html('('+CreateProfile.oComments.length+')');
$('.view_more_comments').click(function(){
tb_show(null,DSMDOMAIN_URL+'/'+Global.DSMId+'/comments.html?height=500&width=600' , false);
});
}
}
Can you post the DSM plugin or a url to it too?
ASKER
I'll see if I can get that but I doubt I will be able to have access to it ... but I'll check. Sorry for that.
JSON.parse method returns an object or an array. So check your other javascript code where you have defined CreateProfile.oComments. 'o' could mean an object.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>>So check your other javascript code where you have defined CreateProfile.oComments.
I was looking through the code again and from what I can tell, the code I originally posted is the first time 'CreateProfile.oComments' appears.
Should I be looking the variable to be established somewhere such as:
var CreateProfile = ???
I was looking through the code again and from what I can tell, the code I originally posted is the first time 'CreateProfile.oComments' appears.
Should I be looking the variable to be established somewhere such as:
var CreateProfile = ???
ASKER
I spoke too soon! I think I found it, check out the code attached and let me know. Fyi this is directly above (i.e right before) the original code I posted
CreateProfile={
maxWidthUnit:460,
objJson : new Array(),
arrAtributos: new Array(),
divContestant:' ',
divContentProfile:'',
divCol_left:' ',
divCol_right:' ',
divSlide:' ',
oComments: null,
divWidget:'',
arrayViral :new Array('','Cold:(','Warm','Hot', 'On Fire!'),
linkUserProfile: '',
linkContest:'',
strComment: '',
That is one way to create a Class and instance at same time in javascript and oComments is one of the member of the class i.e. CreateProfile.oComments is a javascript object.
ASKER
>>>That is one way to create a Class and instance at same time in javascript
So basically, I'm looking at OOP with jQuery?
So basically, I'm looking at OOP with jQuery?
OOP in Javascript: http://www.phpied.com/3-ways-to-define-a-javascript-class/
ASKER
so is that a yes, this is OOP?
ASKER
and to clarify the oComments: could they have just as well written simply 'comments' and left out the 'o'? Or is it a better practice to include the o to define the value contained by the variable, as a BurnieP stated in a previous comment?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I would ask for clarification of one more point and then I would close out this question: when this code creates class and instance (see code below), I notice what seem to be empty variables i.e. divContestant: ' ', divCol_left: ' ', etc.
Are these empty by design so that they are ready to receive user input data from the website as delivered through JSON?
Fyi, if you think this additional question is outside the scope of my original post let me know and I will close out this question and post a new question.
Are these empty by design so that they are ready to receive user input data from the website as delivered through JSON?
Fyi, if you think this additional question is outside the scope of my original post let me know and I will close out this question and post a new question.
CreateProfile={
maxWidthUnit:460,
objJson : new Array(),
arrAtributos: new Array(),
divContestant:' ',
divContentProfile:'',
divCol_left:' ',
divCol_right:' ',
divSlide:' ',
oComments: null,
divWidget:'',
arrayViral :new Array('','Cold:(','Warm','Hot', 'On Fire!'),
linkUserProfile: '',
linkContest:'',
strComment: '',
The class members are initialized as per the need and context in which the class was designed. So it could have bee divContestant:'something' if that was what required and it has nothing to do with JSON.
From the code the Class member that is used for JSON output is oComments only.
From the code the Class member that is used for JSON output is oComments only.
ASKER
Thanks for all the help ...