Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3324)

Issue 181091: localize functions into namespaces

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 4 months ago by calidion
Modified:
7 years, 4 months ago
Reviewers:
xan, weiliu, baiming, leio.chen, lychen, qiaojian
CC:
xinxing_google.com, lishuangfeng_gmail.com
Base URL:
http://scheduleeditor.googlecode.com/svn/trunk/python/
Visibility:
Public.

Patch Set 1 #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+632 lines, -386 lines) Patch
A gtfsscheduleviewer/files/data.js View 1 chunk +297 lines, -0 lines 1 comment Download
A gtfsscheduleviewer/files/gtfs.js View 1 chunk +13 lines, -0 lines 0 comments Download
M gtfsscheduleviewer/files/index.html View 2 chunks +4 lines, -0 lines 0 comments Download
M gtfsscheduleviewer/files/route.js View 2 chunks +67 lines, -13 lines 0 comments Download
M gtfsscheduleviewer/files/style.css View 2 chunks +1 line, -3 lines 0 comments Download
M gtfsscheduleviewer/files/transit_editor.js View 6 chunks +6 lines, -369 lines 0 comments Download
M gtfsscheduleviewer/files/trip.js View 1 chunk +1 line, -1 line 0 comments Download
A gtfsscheduleviewer/files/util.js View 1 chunk +243 lines, -0 lines 0 comments Download

Messages

Total messages: 3
calidion
javascript update
14 years, 4 months ago (2009-12-29 10:01:38 UTC) #1
calidion
this is the initial update of javascript, the next step would introduce big changes for ...
14 years, 4 months ago (2009-12-29 10:06:13 UTC) #2
baiming
14 years, 4 months ago (2009-12-29 11:04:50 UTC) #3
http://codereview.appspot.com/181091/diff/1/2
File gtfsscheduleviewer/files/data.js (right):

http://codereview.appspot.com/181091/diff/1/2#newcode1
gtfsscheduleviewer/files/data.js:1: (function(gtfs){
Very curious why you use namespace in this way, that embrace all the definitions
in a function then assign them to to parameter "gtfs".

Here the only benefit I can see is you can use shortcuts in the code, just as
you do for "$", "Select", etc. Is there any other specific reasons?

Anyway, I think it is not the typical Javascript way to use namespace. The more
common style is

gtfs.data = {};

gtfs.Base = function() {
  this.fetcher = new gtfs.util.rpc.Fetcher;  // Use the full namespace path
};

gtfs.Base.prototype.foo = function() {
  // or make shortcuts in a particular function body
  var Select = gtfs.util.dom.Select;
  var s = new Select();
};

For things like "$" that are used very widely, you can make the shortcut after
where you define gtfs.util.dom.byId, that can be used all over the code, not
only this file.

Also, using the wrapping function is hard to understand, especially to those who
are not as familiar with Javascript as you.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b