Javascript – How do you call a function inside a class from within that class?

There are two main problems

  1. The MIME type is text/javascript, not text/jscript
  2. You are defining the method after you try to call it

So:

  function MyObject() {
    this.MyMethod = function () {
      alert('It works');
    }
    this.MyMethod(); //should now work
  }

  var test = new MyObject();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)