Solved

What does this mean in jQuery?

Posted on 2011-02-20
15
1,087 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
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!

 
LVL 16

Accepted Solution

by:
BurnieP earned 100 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 400 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Chrome: Debugging AJAX call 6 39
Json and ajax javascript 24 26
Why is my select returning NaN 23 46
ajax post without refreshing whole page 10 25
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

710 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