Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Helllo people I'm now developing an instant messaging system but I'm a little confused : I can't decide which approach do I have to choose!

Here is a code and I want you to tell me what is good/bad with this programming approach: one friend of mine said it's difficult to read, but It works

/*! | (c) 2012, 2013 by Bellashh*/
 /// <reference path="jquery-2.0.0-vsdoc.js" />
$(document).ready(function () {
  var ChatProvider = {
    "Friends": [],
    "People": [],
    "Conferences": [],
    "UI": {},
    "Utils": {
      "functions": {
        "alert": function (str) {
          alert(str);
        } /*ChatProvider.Utils.functions.alert*/ ,

        "addFriend": function (friend) {
          ChatProvider.Friends.push(friend);
          alert(ChatProvider.Friends.pop().Names);
        } /*ChatProvider.Utils.functions.addFriend*/ ,

      } /*ChatProvider.Utils.functions*/ ,

      "events": {} /*ChatProvider.Utils.events*/ ,

      "settings": {

      } /*ChatProvider.Utils.settings*/
    }
  } //var ChatProvider

  ChatProvider.Utils.functions.addFriend({
    "Names": "bellash"
  });

}); //$(document).ready

ps: for visibility sake, I added some space between line separating objects' properties

share|improve this question
Quick question, from a user's (not developer's) point of view: How do we access Friends, People and Conferences? Do we get them through a function or do we access the arrays directly? – Joseph the Dreamer Apr 25 at 16:37
1  
Is this the real code you want reviewed, or some kind of example? I ask because addFriend pushes something onto the Friends array and then immediately pops it back off, which makes no sense, and the alert function seems contrived; it just wraps window.alert. In other words, it wouldn't do much good to review this code, as the code doesn't do anything useful. – Dagg Apr 25 at 18:34
Dagg It is only an example. But I wonder if this is the best approach of coding in javascript instead of creating(bubling) separated functions in a .js file, my approach is good because it avoids conflicts between js file: am I wrong ? @JosephtheDreamer for example, to access the Friends array, you just need to write ChatProvider.Friends[index] ... – Ada Bell'h Mon Trésor Apr 29 at 11:23

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.