Javascript class methods

My understanding of javascript object methods (pre-ES6) from Douglas Crockford’s post.

Public

Can’t access private members of the object

Anything created with this.xyz inside the constructor, or

Any methods added by MyObject.prototype.myMethod outside the constructor.

Private

Not accessible from outside the object definition (e.g. as myObj.myMethod())

Any variables or functions created inside the constructor with var or function abc(){...}.

Privileged

(I.e. publicly accessible, but can access private members)1

Methods declared with this.myMethod = function()... inside the constructor.

Continue reading

Installing RCurl on linux

Will keep failing without providing a valid reason.

The reason is lack of a system library – libcurl4-openssl-dev.

Install the library from default sources:

sudo apt-get install libcurl4-openssl-dev

Now, install package RCurl inside R again, and we’re ready to go

Note to self: Use curlies!

This small block of code – it looks clean, and easy to understand

signout: function(callback){
  dropbox.client.signOut(function(error){

    if(error)
      if(callback) callback(false, showError(error));
    
    else
      resetLocalStorage(true, function(){
        if(callback) callback(true);
      });

  });
}

Sadly, it’s also buggy.

When I started programming in javascript, I’d come from a C & Java background, so I encapsulated everything in curlies.

Then sometime later, I started dabbling in Python for work related data processing. I loved how indentation was used to identify code blocks in Python. Didn’t need curlies cluttering everything.

Soon after I discovered that single statements following a loop command (for…) or a conditional (if… else…) didn’t need to be encapsulated inside curlies either. If there was just one statement, you could write it straight after – in same line, or a following one, with any amount of indentation.

Recently, I’ve become addicted to this style of coding. I don’t like unnecessary curlies cluttering the code, and I get rid of them quite aggressively.

Too aggressively as this example shows.

Looking at the code, it appears that the else statement triggers when there isn’t an error. However, in reality, the js parser attaches that else to the if(callback) inside the error conditional.

The correct way to write this is:

signout: function(callback){
  dropbox.client.signOut(function(error){
    
    if(error){
      if(callback) callback(false, showError(error));
    }
    
    else
      resetLocalStorage(true, function(){
        if(callback) callback(true);
      });
    
  });
}

Offline Testing In Chrome

Offline - No Wifi
Offline testing in Chrome – No more WiFi toggling

Despite ever expanding web of internet connectivity, no modern web app can expect not to work decently when offline.

Testing offline functionality, though, can be a bit of a bummer for people like me who develop almost exclusively in/for Google Chrome – unlike the old Internet Explorer, it doesn’t have a quick to access ‘Offline Mode’.

Not being a professional developer, I didn’t have extensive tools at my service to test my app in offline mode, and switching WiFi off-on was becoming tiresome. This is the solution I’ve ended up with, and if you’re looking for offline testing in Chrome, here’s an easy way:

1. Install the Proxy SwitchySharp extension from Chrome Web Store.

2. In extension’s settings, set up a proxy to a non-existent IP Address, preferably on your local network. You could even set it to localhost/127.0.0.1 if you aren’t running a server on local machine.

Proxy Switchy Sharp Settings
Proxy SwitchySharp Extension Settings

3. Now every time you need to switch to offline mode, all you have to do is go to the extension’s browser button, and select the local-profile you created.

 

Browser Button - Select Proxy
Browser Button – Select proxy to go offline.

4. When you want to go back on-line, just select ‘Direct Connection’ or, if you have a corporate proxy, then that.

That’s it! No more toggling WiFi to test offline mode for your web apps.

Joy

Just got the 1st cut of ConvertIt extension working in the browser. Nothing spectacular, doesn’t even filter anything yet, still it’s a source of joy bounding on exhilaration. Joy of seeing it in action :)

Now on with the hard work of actually getting it to do something useful.

Posted from WordPress for Android

CSS3

Finished the W3C tutorial on this yesterday. Then prepared 1st cut outlines (web, mobile, mobile-no-js) of the interface designs for app today.

Now that I’m thinking of implementation, I’ve no idea how to do that!

Back to Google, I guess. And then more reading.

Tutorials

This is a learning weekend and I have tutorials on CSS, CSS3, jQuery and AJAX lined up.

I like these W3CSchools tutorials as they fit my learning method perfectly – short and simple with plenty of try-it-out code samples. That allows me to quickly get a gist of the language and get started working with it. Then I can learn all the powerful and advanced features as and when I need them. This reminds me, how different my current learning methodology is from when I was a full-time tech student. Back then, I use to run through a full book, or many books, on a programming language before attempting to write any serious code with it. Guess I had the liberty of almost unlimited time and no pressure to deliver back then. Then everything was a deep dive. Now, they are all dip sticks.

Anyway, just finished the CSS tutorial. 1 gone, 3 to go.