Home > Web Front-end > JS Tutorial > JS study notes to prevent naming conflicts_javascript skills

JS study notes to prevent naming conflicts_javascript skills

WBOY
Release: 2016-05-16 18:48:48
Original
1100 people have browsed it

To prevent naming conflicts, you can build your own code base.
Just want to
Js code

Copy code The code is as follows:

ziggy_js= function(){}
ziggy_js.ui=function(){}
ziggy_js.ui.alerts=function(){}
ziggy_js.ui.alerts.showErrorAlert=function(){
alert ("An error occurred");
}
ziggy_js.ui.alerts.showErrorAlert();
//To define the class in it
ziggy_js.ui.alerts.messageDisplayer=function(inMsg) {
this.msg=inMsg;
this.toString=function(){
return "msg=" this.msg;
}
}
var v=new ziggy_js. ui.alerts.messageDisplayer("hello");
alert(v);
ziggy_js=function(){}
ziggy_js.ui=function(){}
ziggy_js.ui.alerts= function(){}
ziggy_js.ui.alerts.showErrorAlert=function(){
alert("An error occurred");
}
ziggy_js.ui.alerts.showErrorAlert();
//You can also define the class
ziggy_js.ui.alerts.messageDisplayer=function(inMsg){
this.msg=inMsg;
this.toString=function(){
return "msg=" this.msg;
}
}
var v=new ziggy_js.ui.alerts.messageDisplayer("hello");
alert(v);

In this way, you build your own code base. Of course, there is still some work to do before creating. You can also import it directly into the page
Just like the package in java
First of all, you need to judge whether ziggy has been used by others
Js code
Copy code The code is as follows:

//Write
if(typeof in ziggy_js.string.js ziggy_js=='undefined'){
ziggy_js=function(){};
}
ziggy_js.string=function(){}
ziggy_js.string.test=function(inMsg){
alert(inMsg);
}
//You can import

//In ziggy_js In .string.js write
if(typeof ziggy_js=='undefined'){
ziggy_js=function(){};
}
ziggy_js.string=function(){}
ziggy_js.string.test=function(inMsg){
alert(inMsg);
}
//You can import


Create the package ziggy_js.array that handles arrays
Js code
Copy code The code is as follows:

ziggy_js.array=function(){}
//copy an array
ziggy_js.array.copyArray=function(inSrcArray,inDestArray){
var i;
for(i=0;iinDestArray.push(inSrcArrsy[i]);
}
return inDestArray;
}/ /end copyArray
ziggy_js.array.findInArray=function(inArray,inValue){
var i;
for(i=0;iif(inArray[ i]==inValue){
return i;
}
}
return -1;
}//end findInArray
.....
ziggy_js.array =function(){}
//copy an array
ziggy_js.array.copyArray=function(inSrcArray,inDestArray){
var i;
for(i=0;iinDestArray.push(inSrcArrsy[i]);
}
return inDestArray;
}//end copyArray
ziggy_js.array.findInArray=function(inArray,inValue) {
var i;
for(i=0;iif(inArray[i]==inValue){
return i;
}
}
return -1;
}//end findInArray

.....
Create ziggy_js.browser to get browser information
Js code
Copy code The code is as follows:

ziggy_js.browser=function(){}
ziggy_js .browser.getBrowserIdentity=function(){
return navigator.appName " " navigator.appVersion;
}//end getBrowserIdentity
var brow=ziggy_js.browser.getBrowserIdentity();
alert(brow );
ziggy_js.browser=function(){}
ziggy_js.browser.getBrowserIdentity=function(){
return navigator.appName " " navigator.appVersion;
}//end getBrowserIdentity
var brow=ziggy_js.browser.getBrowserIdentity();
alert(brow);

Package for processing time.
Js code
Copy code The code is as follows:

ziggy_js.dateTime=function(){}
ziggy_js.dateTime.isLeapYear=function(inYear){
if((inYear%4==0&&inYear0!=0)||inYear@0==0){
return true;
}else{
return false;
}
}//end isLeapYear
ziggy_js.dateTime.getNumberDaysInMonth=function(inMonth,inYear){
inMonth=inMonth-1;
var leap_year=this.isLeapYear(inYear);
if(leap_year){
leap_year=1;
}else{
leap_year=0;
}
if(inMonth==3||inMonth==5||inMonth==8||inMonth==10){
return 30;
}else if(inMonth==1){
return 28 leap_year;
}else{
return 31;
}
}//end getNumberDaysInMonth
var days=ziggy_js.dateTime.getNumberDaysInMonth(2,2007);
alert(days);
ziggy_js.dateTime=function(){}
ziggy_js.dateTime.isLeapYear=function(inYear){
if((inYear%4==0&&inYear0!=0)||inYear@0==0){
return true;
}else{
return false;
}
}//end isLeapYear
ziggy_js.dateTime.getNumberDaysInMonth=function(inMonth,inYear){
inMonth=inMonth-1;
var leap_year=this.isLeapYear(inYear);
if(leap_year){
leap_year=1;
}else{
leap_year=0;
}
if(inMonth==3||inMonth==5||inMonth==8||inMonth==10){
return 30;
}else if(inMonth==1){
return 28 leap_year;
}else{
return 31;
}
}//end getNumberDaysInMonth
var days=ziggy_js.dateTime.getNumberDaysInMonth(2,2007);
alert(days);

慢慢完善
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template