Home Java javaTutorial How to set the main function of java

How to set the main function of java

May 03, 2023 pm 07:22 PM
java

The following are the main control functions and some public methods. Including throwing exceptions and logging. Expand, traverse. Set method model path. Get the model (must be set before you can get it, otherwise an exception will be thrown) to judge (data).

Correction

(function(window,undefined){  var_toString = {}.toString,  _is,  _writeScript,  _listUrl,  _scriptMap = {  method_url : {},//method --> url <method : url ><1 : 1 >  url_method : {},//url --> method <url : [method,method] ><1 : n >  visited : {},  writted : {},  wait_write:[]  },  _readyFnx = [],  alfred = function(){//自己单独使用也可以。象jquery  alfred.ready.apply(window,arguments);  };  //私有函数开始  _is = function(it,type){//复杂的可以自己进行设置。正则匹配。  returntype.test(_toString.call(it).toLowerCase());  };  _waitReady = function(){  //等结束。如果结束了。直接跳出循环。其实就是利用JS的这个特性。  if(document.readyState != "loaded" &&document.readyState != "complete")  {  vartime = setTimeout(arguments.callee,0);  return;  }  clearTimeout(time);  }  _checkReady = function(){  //处理参数  for(vari=0;i<arguments.length;i++)  {  _readyFnx.push(arguments[i]);  }  varcallback = _readyFnx.shift();  //支持高级事件的  if(document.addEventListener)  {  document.addEventListener("DOMContentLoaded",function(){  _waitReady();  document.removeEventListener("DOMContentLoaded",arguments.callee,false);  callback.apply(window,_readyFnx);  });  returnthis;  }  //支持事件则用事件处理 IE  if(document.attachEvent)  {  document.attachEvent( "onreadystatechange", function(){  _waitReady();  document.detachEvent( "onreadystatechange",arguments.callee);  callback.apply(window,_readyFnx);  });  returnthis;  }  //不支持的则看不在 iframe 下时候的特殊属性。看 JSCRIPT MSDN。  if(document.documentElement.doScroll &&window == window.top)  {  try {  document.documentElement.doScroll("left","top");  }  catch(e)  {  setTimeout(arguments.callee, 0);  return;}  callback.apply(window,_readyFnx);  returnthis;  }  };  _listUrl = function(){  varl = _scriptMap.visited,i;  //对我们的URL 进行筛选 。主要防止多次添加访问过的依赖库。  for(i inl){  if(!_scriptMap.writted[i])  {  _scriptMap.wait_write.push(i);  }  }  _scriptMap.wait_write.reverse();  _writeScript();  };  _writeScript = function(){  //写入我们的JS 了。  varhead = document.getElementsByTagName("head").item(0),len = _scriptMap.wait_write.length;  for(vari;_scriptMap.wait_write.length&&(i=_scriptMap.wait_write.shift());) {  varscript = document.createElement("script"),  url = i || "";  script.setAttribute("async",true);//高级浏览器支持HTML5特性  script.setAttribute("type","text/javascript");  script.setAttribute("src",url);  head.appendChild(script);  _scriptMap.writted[url] = true;//这里无所谓,只要有这个URL就可以  };  };  alfred.extend = function(){  vardeep = false,  len,  options, name, src, copy, copyIsArray, clone,  target = arguments[0] || {},  i = 1;  len = arguments.length;  if(!len)  {  returnthis;  }  if(alfred.isBoolean(target))  {  deep = arguments[0];  to = arguments[1];  i = 2;  }  if(!(alfred.isObject(target) || alfred.isFunction(target))) {  target = {};  }  if(len = i)  {  target = this;  --i;  }  for(;i<len;i++) {  if((options=arguments[i])!==null)  {  for(name inoptions) {  copy = options[name];  src = target[name];  if(src){throw"Becareful : you are rewrite the "+_handle+"."+name+"!"}  if(copy===target) {continue}  if(deep &&copy; &&(alfred.isObject(copy) || (copyIsArray = alfred.isArray(copy))))  {  if(copyIsArray)  {  copyIsArray = false;  clone = src &&alfred.isArray(src) ? src : [];  }  else {  clone = src &&alfred.isObject(src) ? src : [];  }  target[ name ] = alfred.extend( deep, clone, copy );  }  elseif( copy !== undefined )  {  target[name] = copy;  }  }  }  }  };  alfred.isNumber = function(it){return_is(it,/^[object number]$/)};  alfred.isString = function(it){return_is(it,/^[object string]$/)};  alfred.isFunction = function(it){return_is(it,/^[object function]$/)};  alfred.isObject = function(it){return_is(it,/^[object object]$/)};  alfred.isArray = function(it){return_is(it,/^[object array]$/)};  alfred.isBoolean = function(it){returntypeofit ===&#39;boolean&#39;};  alfred.isDom = function(it){return_is(it,/^[object htmlw+]$/)};  alfred.extend({  author : "alfred",  version : 1.01,  global : window,  doc : window.document,  reset : function(it){alfred.global[it]=alfred;},  log : function()  {  if(window.console &&console.log)  {  returnconsole.log.apply(window,arguments)  }  },  error : function(name,value)  {  throw{"name":name,"message":value};  },  require : function(method)  {  varm2u = _scriptMap.method_url,  u2m = _scriptMap.url_method,  r;  if(!(m2u[method])){throw"Error : you need setMethod first"}  if(!_scriptMap.visited[m2u[method][0]] &&!_scriptMap.writted[m2u[method][0]]) {  //haven&#39;t be visited or write  _scriptMap.visited[m2u[method][0]] = true;  //use an beautiful code in here  for(; m2u[method][1].length &&(r=m2u[method][1].shift());)  {  alfred.require(r);  }  _listUrl();  }  },  setMethod : function(url,method,rely)  {  vari, method = alfred.isArray(method)? method:[method],  rely = alfred.isArray(rely)?rely:[rely];  if(url &&!_scriptMap.url_method[url]){  _scriptMap.url_method[url] = method;   for(;method.length&&(i=method.shift());) {  _scriptMap.method_url[i] = {"0" : url, "1" : rely};  }  returnthis;  }  throw"Error : you are setMethod in an old method";  },  ready : function(){  _checkReady.apply(window,arguments);  },  each : function(arg,callback){  for(vari inarg){  if(arg[i])  {  callback.call(arg[i],i);  }  }  returnarg;  }  });  window.alfred = alfred;  })(window)
Copy after login

Introduce this file first when using it. Then you need to set it up like this

alfred.setMethod("basic.js",["alfred","alfred.global","alfred.doc","alfred.reset","alfred.log","alfred.isNumber",  "alfred.isFunction","alfred.isArray","alfred.isObject","alfred.isString","alfred.isBoolean",  "alfred.require","alfred.setMethod","alfred.extend"],[]);
Copy after login

After setting it up, you can tell the following JS that I have provided these methods. Just type alfred.require("alfred.reset"); to pull the file into the page and register it.

This is what the page looks like.

<!DOCTYPE html> <html> <head> <title> </title> </head> <body> <script type="text/javascript" src="base.js"></script> <script type="text/javascript" src="deps.js"></script> <script type="text/javascript"> alfred.reset("$");  $.require("alfred.dom");  $(function(){  vara = $.dom("<div id=&#39;test&#39; style=&#39;width:200px;height:200px;background:red;&#39;> adf</div>");  $.dom("body").prepend(a);  })  </script> </body> </html>
Copy after login

alfred.reset is for the convenience of setting the method name. In this way we can use it almost like jquery.

alfred.reset("$");

$.require("alfred.dom");

$.dom("div a span:first-child ").append("hello alfred");

can be used like this.

The above is the detailed content of How to set the main function of java. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and Functionality PHP vs. Python: Core Features and Functionality Apr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP: The Foundation of Many Websites PHP: The Foundation of Many Websites Apr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles