How can I call the javascript class outiside class method

var Card = YClass.extend({
 // define Class Name
 className:'Card', 
 // class level default options
 config:{
  id:'cardid', 
  container:'body',   // id of container in which to render the user
  render:false,
  template: 'tmpl_card',  // id of template used to render user
  debug:false   
 },
setposition:function() {
  var i=1;
  var xpos=10;
  var ypos=15;
  var recvflag=false;
}
);

how can I call the positioning function that I am trying to use Card.setposition ();

but it gives me an error that setposition is not defined why ??

+3
source share
2 answers

This is not a jQuery thing, it is a YClass thing. I do not know what YClass is, but I assume that it defines classes that you then instantiate:

var c = new Card();
c.setposition();

It will be like the Resig “ Simple JavaScript InheritanceClassthing, Prototype or system I describe here . Class

If you need a container with some functions on it, you can just do it directly:

var Card = {
    setposition: function() {
        alert("Hi there!");
    };
};
Card.setposition(); // alerts "Hi there!"

... , YClass - .

+2

:

Card.prototype.setPosition();

:

JavaScript () . . Class , , Class. prototype. , Class. prototype. , .method, . Class , prototype.

+1

Source: https://habr.com/ru/post/1765965/


All Articles