Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <script>
    
$(document).ready(function () {
  var MyConstructor = function () {};
  MyConstructor.prototype = {
    init: function () {
      //logs 'doing stuff'
      this.doStuff();
      //the 'this' now refers to the constructor's 'this'   
      $('.my-element').click($.proxy(function (event) {
        //'this' should work
        this.doStuff();
        //to reference back the dom object
        var _this = event.target;
       }, this));
    },
    doStuff: function () {
      console.log('doing stuff');
    }
  };
  MyConstructor.prototype.init();
});
  </script>
  <p class="my-element">Some words.</p>
</body>
</html>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers