Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What does this mean in jQuery?

Posted on 2011-02-20
15
Medium Priority
?
1,089 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 75

Expert Comment

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

Author Comment

by:max7
ID: 34938236
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
ID: 34938330
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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 16

Accepted Solution

by:
BurnieP earned 400 total points
ID: 34938333
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
ID: 34938411
>>>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
ID: 34938432
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
ID: 34938550
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
 
LVL 1

Author Comment

by:max7
ID: 34938763
>>>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
ID: 34938902
0
 
LVL 1

Author Comment

by:max7
ID: 34938933
so is that a yes, this is OOP?
0
 
LVL 1

Author Comment

by:max7
ID: 34938997
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 1600 total points
ID: 34940046
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
ID: 34944476
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
ID: 34945394
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
ID: 34945574
Thanks for all the help ...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

722 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