Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.92 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var captures = (function() {
  2.        
  3.         var path = "/tsp/";
  4.        
  5.         var comments = path + "delete/capture:captureId/comment:commentId"
  6.        
  7.       // you return a closure object with key => values where the values are the functions and the keys are the names of the functions
  8.      // everything in js is an object with a prototype. that prototype is defined as just a hash of keys and values {}    var  o = { foo: 1 };
  9.      // you can return objects to. here our are closing over some properties defined in your captures function encapsulated in new functions
  10.       return {
  11.         addComment: function(id, timestamp, text) {
  12.                 alert('add comment');
  13.         },
  14.        
  15.         deleteComment: function(captureId, commentId, success, error) {
  16.                 var url = comments.replace("captureId",captureId).replace("commentId",commentId);
  17.                 var post = {
  18.                         type:'POST',
  19.                         url: url,
  20.                         success: success,
  21.                         error: error
  22.                 };
  23.                 $.ajax(post);
  24.         }
  25.      };
  26.        
  27. })();