1

Is it possible to and can anyone give me an example of using Typescript to write a jQuery plugin. I feel like the plugin structure would be much more maintainable and readable if plugins were written as classes, but I can't find any examples of that online. My idea is basically as follows, but I don't know if it will work.

class Modalify{

  constructor(public options: Object) {}

  public doSomething() {
    console.log(this.options);
  }

}

$.fn.modalify = Modalify;

edit this is not a duplicate because I am specifically looking for the es2015 way of doing this. The possible duplicate is using regular javascript and just trying to add typing support

2
  • It is possible and your way looks fine. However the answer to this question would be primarily opinion based and likely to generate a lot unnecessary of discussion. If you seek to improve your code you can use the codereview site codereview.stackexchange.com Commented Apr 22, 2016 at 21:33
  • @KhairulIslam see my edit. The post you tagged as the duplicate is still using es5 syntax. I am looking to use classes with jQuery plugins Commented Apr 22, 2016 at 22:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.