0

(function() {
  let create = {

    init() {
      this.cacheDom();
      this.bindEvent();
    },

    bindEvent() {
      $(this.$content_buttons).click(function() {
        create.preformAction(this);
      });
    },

    cacheDom() {
      this.$content_buttons = $('.content_button');
    },

    preformAction(el) {
      alert('its class is ' + $(el).attr('class'));
    }
  };
  create.init();
}());

consider my code above I am able to access performAction method of create object by doing this create.performAction . is there any other way of doing. thanks in advance.

Jaromanda X
  • 53,868
  • 5
  • 73
  • 87
zeeeuu
  • 19
  • 4

1 Answers1

2

try it:

(function() {
 let create = {

init() {
  this.cacheDom();
  this.bindEvent();
},

bindEvent() {

  $(this.$content_buttons).click(function() {
    create.preformAction(this);
  });
},

cacheDom() {
  this.$content_buttons = $('.content_button');
},

preformAction(el) {
  alert('its class is ' + $(el).attr('class'));
}
 };
  create.init();
}());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="content_button class1">click1</button>
<button class="content_button class2">click2</button>
Mehran Hafizi
  • 2,392
  • 2
  • 12
  • 14