0

in javascript I have one class

MyClass = {
...
}

In some part of the code, I would like to do MyClass.SomeFunction(arg1, arg2, ...);

using prototype (maybe) I would like to take the name took and arguments and do a generic function.

Objective it is to build something similar like PageMethods like in asp.net to have a clear code.

Can you help me to start? maybe giving some web page with samples or tutorial.

In javascript I was thinking to use $.fn but I don't know how to start.

The idea it is have a generic function class inside MyClass, I dont know if it is possible, maybe using jquery

Dave
  • 7,028
  • 11
  • 35
  • 58
  • 1
    Check this link out, the first section may prove helpful. http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#designpatternsjavascript – Tony Sep 17 '14 at 12:51
  • Maybe the following can help you understand prototype and constructor functions. That and the osmany patterns link posted in the other comment: http://stackoverflow.com/questions/16063394/prototypical-inheritance-writing-up/16063711#16063711 – HMR Sep 17 '14 at 13:20
  • Forget about jQuery and `$.fn` instantly. They're no good examples for proper design. – Bergi Sep 17 '14 at 13:46
  • What exactly do you mean by "*take the name took and arguments and do a generic function*"? Can you give a more detailed explanation of what you want to do? – Bergi Sep 17 '14 at 13:47
  • when I do something like MyClass.SomeFunction(arg1, arg2, ...); to getin the generic function the name to call it and in an array the arguments, and build the call inside the generic function – Dave Sep 17 '14 at 13:51
  • You mean `SomeFunction` is not explicitly declared, and its name isn't known before the call either? – Bergi Sep 17 '14 at 13:55
  • yes and in a automatic prototype inside function get the call and throw some ajax. looks like something like PageMethod in asp.net using webforms – Dave Sep 17 '14 at 14:03
  • No, that's impossible in JavaScript. – Bergi Sep 17 '14 at 14:07

0 Answers0