www.webdeveloper.com
Results 1 to 5 of 5

Thread: static class functions

  1. #1
    Join Date
    Apr 2005
    Posts
    210

    Angry static class functions

    Add 2 static functions in the class:
    Code:
    function ClassCommon()
    {
    	showNode = function(node,show)
    	{
                 ...
    	}
    	moveNode = function(node)
    	{
                 ...
    	}
    }
    or:
    Code:
    function ClassCommon()
    {
    	ClassCommon.showNode = function(node,show)
    	{
                 ...
    	}
    	ClassCommon.moveNode = function(node)
    	{
                 ...
    	}
    }
    Which one is correct? (static functions)

    Actually, both are not working on my code.

    Thanks for corrections.

    BTW: use in this way
    ClassCommon.showNode(node, true);


    .
    Last edited by html20009876; 05-11-2012 at 05:04 PM.

  2. #2
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    ClassCommon doesn't yet exist, as far as I can tell, until the interpretor is outside the definition block. Though not as pretty as in other languages, you can write it like so:

    PHP Code:
    function ClassCommon()
    {
    }

    ClassCommon.showNode = function(node,show)
    {
      ...
    }

    ClassCommon.moveNode = function(node)
    {
      ...


  3. #3
    Join Date
    Apr 2005
    Posts
    210
    Hi svidgen,

    Thanks, I will test.

    But, I like format similar to java or c++.
    May class static-function be written inside a class?

    .

  4. #4
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    Quote Originally Posted by html20009876 View Post
    May class static-function be written inside a class?
    Not naturally, no. You'd have to use libraries that let you use a nicer syntax for defining classes. There's no one standardized library I can point you toward. Most of the major libraries -- such as YUI, Closure, and Dojo -- each have their own
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  5. #5
    Join Date
    Aug 2007
    Posts
    3,767
    Quote Originally Posted by html20009876 View Post
    But, I like format similar to java or c++.
    Therein lies your problem. JavaScript doesn't have classical inheritance, it has prototypical inheritance, so if you are expecting things to work like Java or C++, you will be disappointed. Even the method described above is not fully equivalent to static methods, it's merely storing a few functions as members of the ClassCommon object, that is the Function object, which you can do for any object.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles