Solved

What does this mean in jQuery?

Posted on 2011-02-20
15
1,081 Views
Last Modified: 2012-05-11
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
Comment
Question by:max7
15 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Can you post the DSM plugin or a url to it too?
0
 
LVL 1

Author Comment

by:max7
Comment Utility
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
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
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
 
LVL 16

Accepted Solution

by:
BurnieP earned 100 total points
Comment Utility
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
 
LVL 1

Author Comment

by:max7
Comment Utility
>>>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
 
LVL 1

Author Comment

by:max7
Comment Utility
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
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Author Comment

by:max7
Comment Utility
>>>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
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
0
 
LVL 1

Author Comment

by:max7
Comment Utility
so is that a yes, this is OOP?
0
 
LVL 1

Author Comment

by:max7
Comment Utility
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
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 400 total points
Comment Utility
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
 
LVL 1

Author Comment

by:max7
Comment Utility
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
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
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
 
LVL 1

Author Closing Comment

by:max7
Comment Utility
Thanks for all the help ...
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now