Once

  1. Root
    1. Once

A Once class creates only one instance.

CLASS METHODS

  1. import { defclass, sendmsg, supersend } from 'So-o';
  2.  
  3. defclass('Once', null, 1,
  4.     ['instance'],
  5.     null,

The Once class inherits from the Root class. The class property instance keeps the unique instance of the class. The Once class redefines the class message new.

new
SYNOPSIS

sendmsg(c, 'new'[, arg ...])

DESCRIPTION

The first time new is called, it returns a new instance of c. The following times, it returns this same instance of c.

new passes all the arg parameters of the message to init.

CODE
  1.     {   'new':
  2.             (self, ...args) => {
  3.                 let i = sendmsg(self, 'get', 'instance');
  4.    
  5.                 if (!i) {
  6.                     i = supersend(Once, self, 'new', ...args);
  7.                     sendmsg(self, 'set', 'instance', i);
  8.                 }
  9.    
  10.                 return i;
  11.             }
  12.     },
  13.     null
  14. );

new retrieves the class property instance. If this property has no value yet, new creates a new instance by calling the new method inherited from the Root class with all the arguments of the message and saves the new instance in the class property instance. new returns the instance which was saved or the new instance.

SEE ALSO

Application

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].