1

I'm developing a cordova based mobile application using Backbone and Requirejs. I need to create a wrapper over the cordova's camera plugin. In my project I need a single camera instance so instead of returning a function I'm returning an object from the module as shown below.

define(['underscore', 'deferred'], function (_, Deferred) {

  'use strict';

  var defaultQuality = 50,
    isEditAllowed = false,
    saveToAlbum = false;

  return {

    getPicture: function (options) {

      var deferred = Deferred(),
        cameraOptions = _.extend({
          quality: defaultQuality
        }, options);

      navigator.camera.getPicture(deferred.success, deferred.fail, cameraOptions);
      return deferred.promise();
    },

    capturePicture: function (success, fail, allowEdit, saveToPhotoAlbum) {
      return this.getPicture(success, fail, {
        allowEdit: allowEdit || isEditAllowed,
        saveToPhotoAlbum: saveToPhotoAlbum || saveToAlbum
      });
    },

    getPictureFromAlbum: function (success, fail) {
      return this.getPicture(success, fail, {
        sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM
      });
    },

    getPictureFromLibrary: function (success, fail) {
      return this.getPicture(success, fail, {
        sourceType: Camera.PictureSourceType.PHOTOLIBRARY
      });
    }
  };
});

The above camera module has to be used in a backbone view.

define(['backbone', 'camera'], function(Backbone, ?) {
  //...
});

As per the naming standards in Javascript, do I need to use camelCase (camera) or PascalCase (Camera) naming convention in the function parameter.

VJAI
  • 32,167
  • 23
  • 102
  • 164
  • 2
    I'd use camel case because in JS I only use Pascal case for constructors. – nnnnnn Nov 25 '14 at 11:56
  • If that's the case then we should use `backbone` instead of `Backbone` right? – VJAI Nov 25 '14 at 12:05
  • Well I would, but as a non-Backbone user I don't know if the Backbone community has its own conventions... – nnnnnn Nov 25 '14 at 12:07
  • Backbone is a namespace that wraps all the constructor components like views, models, routers and collections. So for namespaces do you still go with camelcase? – VJAI Nov 25 '14 at 12:11
  • Um...I guess I might use Pascal case for that. And I'd follow what other Backbone users do... – nnnnnn Nov 25 '14 at 12:27

0 Answers0