   escapeHtml: (string) -> string.replace(/</g, "&lt;").replace(/>/g, "&gt;")
 
   # Generates a unique ID
-  createUniqueId: (->
+  createUniqueId: do ->
     id = 0
-    return -> id += 1
-  )()
+    -> id += 1
 
   hasChromePrefix: (url) ->
     chromePrefixes = [ 'about', 'view-source' ]


  # Creates a search URL from the given :query.
  createSearchUrl: (query) ->
    # we need to escape explictely to encode characters like "+" correctly
    "http://www.google.com/search?q=" + encodeURIComponent(query)

  # Converts :string into a google search if it's not already a URL.
  # We don't bother with escaping characters as Chrome will do that for us.
  convertToUrl: (string) ->
    string = string.trim()
    # special-case about:[url] and view-source:[url]
    if Utils.hasChromePrefix string then string
    else
      if (Utils.isUrl(string)) then Utils.createFullUrl(string) else Utils.createSearchUrl(string)

# This creates a new function out of an existing function, where the new function takes fewer arguments.
# This allows us to pass around functions instead of functions + a partial list of arguments.
Function.prototype.curry = ->
  fixedArguments = Array.copy(arguments)
  fn = this
  -> fn.apply(this, fixedArguments.concat(Array.copy(arguments)))


String::startsWith = (str) -> @indexOf(str) == 0

# A very simple method for defining a new class (constructor and methods)
# using a single hash. No support for inheritance is included because we
# really shouldn't need it.
# TODO(philc): remove this.
Class =
  extend: (properties) ->
    newClass = ->
      @init.apply(this, arguments) if @init
      null
    newClass.prototype = properties
    newClass.constructor = newClass
    newClass

globalRoot = window ? global
globalRoot.extend = (hash1, hash2) ->
  for key of hash2
    hash1[key] = hash2[key]
