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 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)

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

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

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Java Program to Find the Volume of Capsule Java Program to Find the Volume of Capsule Feb 07, 2025 am 11:37 AM

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

Create the Future: Java Programming for Absolute Beginners Create the Future: Java Programming for Absolute Beginners Oct 13, 2024 pm 01:32 PM

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

See all articles