Skip to content

Instantly share code, notes, and snippets.

@bulkan
Last active December 18, 2015 22:38
Show Gist options
  • Save bulkan/5855406 to your computer and use it in GitHub Desktop.
Save bulkan/5855406 to your computer and use it in GitHub Desktop.

How to create a reusable JavaScript module for Python developers

Most Python developers will have this notion that JavaScript sucks and it's horrible. It's really easy to blame the language than to learn the quirks. It's true that JavaScript has it's quirks like Python. Each to their own.

Also, as Python developer we spend most of our time writing server side code. Creating a new Django view, updating a Model or debugging a SQL query. As developers we always believed that we are horrible at frontend prettyness. There might be truth to this statement, but if you believe you can't do something or try to improve you will always stay away from it.

I have seen as a Pythonista that when frontend work is needed, we quickly hack away at cobbling together a few $.ajax calls with a few $(elem).fadeIn() without ever thinking of maintainability, readability and abstracting certain functionality into components or modules. With Django we will usually put certain JavaScript into templates and render them. Poor mans abstractions. I'm guilty as charged for doing things like;

{% extend "base.html %}

{% block more_js %}
<script>
  $(document).ready(function() {
  });
</script>
{% end %}

another example

{% include "person.js" %}

{% for person in person %}
  <h1>{{ person.name }}</h1>
{% end for %}

I guess this way of writing JavaScript required us to change our mindset in the way we write front end code. Instead of writing views that render templates with inlined JavaScript.

I heard you like Models & Views, so we put them in your JavaScript

I remember using ExtJS 4 when it first came out not for its pretty widgets (sarcasm) but for its MVC. I distinctly remember how magical it was and how lacking its documentation. But now we have multiple front end JavaScript frameworks with documentation that is better than what I remember ExtJS 4 had.

  • Knockout
  • Angular
  • Ember
  • Backbone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment