OOP extension for Function_javascript skills
// The following is the method used by OOP
// This is very convenient It's obscene...because JS is not an OOP language...
// But the great fans guide us to do this
// Belldandy will bless those who use these methods to OOP...
Function.prototype .inherits = function(base){
//Derivation relationship, prototype is retained
//Only single derivation is supported
this.prototype = new base();
return this;
}
Function.prototype.create = function(){
//The creator of the class is equivalent to using new
//JS does not support the use of call and apply in the constructor, so...
/ /Belldandy, thank you for telling me how to solve this problem...
var _args = [];
for(i=0;i
return eval('new this(' _args.join(',') ')'); //eval is used...Bell, please be nicer next time My idea...
}
Function.prototype.pin = function(pinner,args){
// Register service, or "pin" service
// EventManager can do this
// You can also think of it as implementing an interface with a default implementation...
// For example, pin EventManager can be like this: Class.pin(core.WvwntManager)
args = args || [ ];
pinner.apply(this.prototype,args);
return this;
}
Function.prototype.method = function(name, f) { //Add method, efficient
if (!(f instanceof Function)) throw new Error('Invalid method binding, got type ' typeof f '; expected function');
this.prototype[name] = f;
return this
}
Function.prototype.property = function(name, localName, getter, setter) { //Add properties, you can customize getters and setters
if (!name || !name instanceof String) throw new EnvironmentException('When defining the attribute, the attribute name is not defined or is not a string');
if (!localName || !localName instanceof String) localName = '_local_' name;
if(getter instanceof Function) {
this.prototype['_belldandy_get_' name] = getter;
}
if(setter instanceof Function){
this.prototype['_belldandy_set_' name] = setter;
}
this.prototype[name] = new Function("value , force","
if (!value && !force) {
if (!this['" '_belldandy_get_' name "'] || !this['" '_belldandy_get_' name "'] instanceof Function)
return this['" localName "']; /* when no getter is set*/
else
return this['" '_belldandy_get_ ' name "'].call(this);
} else {
if (!this['" '_belldandy_set_' name "'] || !this['" '_belldandy_set_' name "'] instanceof Function )
this['" localName "'] = value;
else
this['" '_belldandy_set_' name "'].call(this, value);
return this
} ") //Belldandy, forgive me, although this does not produce a closure
return this;
}
Function.prototype.static = function(name,value){ //Static features, including attributes And the method
this[name] = value;
return this;
}
has the following effect:
function foo() { };
foo
.property('a', '_a')
.property('b', '_b', function() { return this._b '.' })
.method('f', function() { dwn(this.a ()) });
function bar(x,y){this.x = x;this.y = y;};
with(bar){
inherits(foo)
method ('g',function(){dwn(this.a() '-' this.b())})
}
var f = new foo();
f.a( 1);
f.b(2);
dwn(f.a());
dwn(f.b());
f.f();
b = bar.create(1,2 );
b.a(4);
b.b(5);
dwn(b.x',' b.y); >

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Function means function. It is a reusable code block with specific functions. It is one of the basic components of a program. It can accept input parameters, perform specific operations, and return results. Its purpose is to encapsulate a reusable block of code. code to improve code reusability and maintainability.

In this article, we will learn about enumerate() function and the purpose of “enumerate()” function in Python. What is the enumerate() function? Python's enumerate() function accepts a data collection as a parameter and returns an enumeration object. Enumeration objects are returned as key-value pairs. The key is the index corresponding to each item, and the value is the items. Syntax enumerate(iterable,start) Parameters iterable - The passed in data collection can be returned as an enumeration object, called iterablestart - As the name suggests, the starting index of the enumeration object is defined by start. if we ignore

Detailed explanation of the role and function of the MySQL.proc table. MySQL is a popular relational database management system. When developers use MySQL, they often involve the creation and management of stored procedures (StoredProcedure). The MySQL.proc table is a very important system table. It stores information related to all stored procedures in the database, including the name, definition, parameters, etc. of the stored procedures. In this article, we will explain in detail the role and functionality of the MySQL.proc table

What is object-oriented programming? Object-oriented programming (OOP) is a programming paradigm that abstracts real-world entities into classes and uses objects to represent these entities. Classes define the properties and behavior of objects, and objects instantiate classes. The main advantage of OOP is that it makes code easier to understand, maintain and reuse. Basic Concepts of OOP The main concepts of OOP include classes, objects, properties and methods. A class is the blueprint of an object, which defines its properties and behavior. An object is an instance of a class and has all the properties and behaviors of the class. Properties are characteristics of an object that can store data. Methods are functions of an object that can operate on the object's data. Advantages of OOP The main advantages of OOP include: Reusability: OOP can make the code more

Go functions are available as methods of objects. Methods are functions associated with an object that provide access to the object's fields and methods. In Go, methods are defined using func(receiver_type)identifier(parameters)return_type syntax. This approach plays an important role in object-oriented programming by providing encapsulation, reuse, and extensibility.

Usage and Function of Vue.use Function Vue is a popular front-end framework that provides many useful features and functions. One of them is the Vue.use function, which allows us to use plugins in Vue applications. This article will introduce the usage and function of the Vue.use function and provide some code examples. The basic usage of the Vue.use function is very simple, just call it before Vue is instantiated, passing in the plugin you want to use as a parameter. Here is a simple example: //Introduce and use the plug-in

The file_exists method checks whether a file or directory exists. It accepts as argument the path of the file or directory to be checked. Here's what it's used for - it's useful when you need to know if a file exists before processing it. This way, when creating a new file, you can use this function to know if the file already exists. Syntax file_exists($file_path) Parameters file_path - Set the path of the file or directory to be checked for existence. Required. Return file_exists() method returns. Returns TrueFalse if the file or directory exists, if the file or directory does not exist Example let us see a check for "candidate.txt" file and even if the file

The clearstatcache() function is used to clear the file status cache. PHP caches the information returned by the following functions −stat()lstat()file_exists()is_writable()is_readable()is_executable()is_file()is_dir()filegroup()fileowner()filesize()filetype()fileperms() What to do To provide better performance. Syntax voidclearstatecache() Parameter NA Return value clearstatcache(
