Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1091
  • Last Modified:

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.


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);
                });
            }
        }

Open in new window

0
max7
Asked:
max7
2 Solutions
 
Michel PlungjanIT ExpertCommented:
Can you post the DSM plugin or a url to it too?
0
 
max7Author Commented:
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.
0
 
guru_samiCommented:
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BurniePCommented:
Normally, when programmers use o in front of a variable name, it means that it is an object.

var oObject as new Object();
var iInteger = 0;
var sString = "text";

etc..

The little letter stands for what type of value the variable contains.
0
 
max7Author Commented:
>>>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 = ???
0
 
max7Author Commented:
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: '',

Open in new window

0
 
guru_samiCommented:
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.
0
 
max7Author Commented:
>>>That is one way to create a Class and instance at same time in javascript

So basically, I'm looking at OOP with jQuery?
0
 
guru_samiCommented:
0
 
max7Author Commented:
so is that a yes, this is OOP?
0
 
max7Author Commented:
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?
0
 
guru_samiCommented:
Yes that is OOP.
'o' is for naming convention. e.g. I have seen variable naming e.g.:
    bAllow - 'b' boolean variable,
    sName - 's' for string variable.
It isn't mandatory and you can simply have "comments".
0
 
max7Author Commented:
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.
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: '',

Open in new window

0
 
guru_samiCommented:
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.
0
 
max7Author Commented:
Thanks for all the help ...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now