JavaScript classes and built-in objects

Source: Internet
Author: User
Tags date definition class definition compact contains inheritance reference window
Javascript| Objects | Built-in objects

Javascript Objects and classes

JavaScript is object-based, not object-oriented programming language, it does not support classes and inheritance, JavaScript in the object-oriented aspect compared with the Java rigorous, it seems very casual.


Creating objects


JavaScript declares a class by implementing a construction method that contains a description of the property and a method definition, and there is no specialized class class definition.

Such as: To declare the construction method of the oven class

function oven (color,type,time)

{This.color=color;

This.type=type;

This.time=time;

This.info=info;

}

function info ()

{Document.writeln ("<B> color:</b>", this.color);

Document.writeln ("<B> type:</b>", This.type);

Document.writeln ("<B> Factory date:</b>", this.time);

}

To create a oven class object instance:

Oven1=new oven ("red", "compact Type", "99.1.1");

Oven2=new oven ("blue", "Elegant Type", "99.10.1");

Oven3=new oven ("yellow", "practical", "2000.1.1");

Jscript1.html:

<HTML>

<HEAD>

<TITLE> "Welcome to buy" </TITLE>

<s cript language= "Javas cript" >

function oven (color,type,time)

{This.color=color;

This.type=type;

This.time=time;

This.info=info;

}

function info ()

{Document.writeln ("<B> color:</b>", This.color, "<BR>");

Document.writeln ("<B> type:</b>", This.type, "<BR>");

Document.writeln ("<B> Factory date:</b>", This.time, "<BR>");

}

</script>

</HEAD>

<BODY>

<H2> Oven Products </H2>

<script>

Oven1=new oven ("red", "compact", "January 1, 1999");

Oven2=new oven ("blue", "Elegant Type", "October 1, 1999");

Oven3=new oven ("yellow", "practical", "January 1, 2000");

</script >

<HR>

<s cript>

Oven1.info ();

</script>

<HR>

<script>

Oven2.info ();

</script>

<HR>

<script>

Oven3.info ();

</script>

<HR>

</BODY>

</HTML>


JavaScript also makes it easy to create an object and optionally add attributes to it in the following ways:

var oven1=new Object ();

Oven1.color= "C1";

Oven1.type= "T1";

Oven1.time= "T1";


The available objects for JavaScript are:


Anchor

Applet

button

CheckBox

Date

Document

Form

History

Link

Location

Math

Password

RadioButton

Reset

Selection

String

Submit

Text

TextArea

Window


Navigator Object Inheritance Tree


Navigator

Window


History

Document


Anchors

Forms

Links

Location


One: Window objects


The Window object is the top-level object of JavaScript, which contains all objects except the Navigator object.


Note: Some methods and properties are available only to browsers that support Javascript1.2.


1. Properties:


Defaultstatus: Sets the status line default string, read-only.


Status: Describes the state line string, which can be read and write.


Frames: An array of objects that contains all the frame in the window, frames.length can get the number of frame.


Frame: A Frame object.


Self: Current window.


Parent: Window or frameset.


Top: The top-level window of the current window.


Name: The names of the windows.


Innerheight: Gives the interior height of the browser window.


Innerwidth: Gives the internal width of the browser window.


Outerheight: Gives the entire browser window height.


Outerwidth: Gives the entire browser window width.


Locationbar: Set display or hide the browser address bar, such as: Locationbar=true


MenuBar: Sets the display or hide the browser menu bar, such as: Menubar=false


Personalbar: Sets the display or hide browser indicator bar, such as: Personalbar=false


ScrollBars: Sets the display or hidden window scroll bar, such as: Scrollbars=true


StatusBar: Sets display or hide the browser status bar, such as: Statusbar=true


Toolbar: Sets the browser toolbar to show or hide, such as: Toolbar=false


Java: Provides access to Java API class properties and methods, such as: Java.lang.Math.random.


Netscape: Provides a reference netscape.* toolkit.


Sun: Provides reference sun.* toolkit.


Documents: The Document object that is currently contained in the window.


Location: Specifies the string of the current document URL.


History: The history object associated with the window.


2. Methods


Alert ("string"): Opens a warning dialog box and displays string information.


Confirm ("string"): Open a dialog box with the OK and Cancel buttons and display string information, select Cancel to return False if the user chooses OK to return true.


Prompt ("string"): Opens a dialog box that displays string information with a single line of text entry fields, and returns the string entered by the user when the dialog box closes. (see window Example 1)


SetTimeout: Time to set an event to occur in milliseconds. (see window examples 2 and 3)


Cleartimeout: Resets the settings made by settimeout.


Captureevent (EventType): Sets the window to capture events of the specified type.


Releaseevents (EventType): Stops capturing the specified type of event.


Handleevent (Event): If Captureevent () is set, events of the specified type are passed to the Handleevent () method.


Focus (): Causes the window to be entered as the focal point.


Blur (): Drops the input focus in the current window.


Stop (): Stops downloading the current file, and quite presses the "Stop" button.


Close (): Closes the window.


Open (Url,name,features,replaceflag): Finds a window or opens a new window. (see window Example 2)


URL: Specifies the resource displayed in the window, and the empty string opens a blank window.


Name: is the window.


Replaceflag: When the value is true, the new window replaces the location of the original window in the history record.


Features: gives a comma-delimited window property value, such as: Menubar=no.


Features


Alwayslowered=yes|no: Whether the window is always under another window.


Alwaysraised=yes|no: Whether the window is always above other windows.


Dependent=yes|no: The window is attached to the parent window, which is also closed when the parent window closes.


Hotkeys=yes|no: Do you want to cancel the hotkey?


Location=yes|no: Whether the current URL is displayed.


Menubar=yes|no: Whether to display the menu bar.


Resizable=yes|no: Allows the user to change the window size.


Scrollbars=yes|no: Whether to bring a scroll bar.


Status=yes|no: Displays the status bar at the bottom of the window.


Titlebar=yes|no: Whether to display the title bar.


Toolbar=yes|no: whether to display toolbars.


Z-lock=yes|no: Whether to fix the window position.


height|innerheight= pixel value: The height of the window content area.


width|innerwidth= pixel Value: Window content area width.


outerheight= pixel value: window height.


outerwidth= Pixel Value: Window width.


screenx= pixel value: The position of the left border of the window.


screeny= pixel value: The window's top border position.


3. Window Events


OnBlur (): When the window loses focus.


Ondragdrop (): When a file or shortcut is dragged to the window.


OnError: When a JavaScript error occurs.


Onfocus (): When the window gets the focus.


OnLoad (): When the browser loads the page.


OnMove (): When the window is moved.


OnResize (): When the window is changed in size.


OnUnload (): When the user leaves the page.


4. Window examples


Case 1:promptdemo.html


<HTML>

<HEAD>

<title>javascript prompt demo</title>

</HEAD>

<BODY>

<script language= "Javascript" >

document.write ("
msg= prompt ("Please enter content:");

document.write (msg+ "</H1>");

Document.close ();

</script>

</BODY>

</HTML>


Case 2:windowdemo.html


<script language= "Javascript" >

function NewWindow ()

{window. open ('.. /script1.htm "," Localwindow "," Toolbar=no,statusbar=no,menubar=no,


Scrollbars=yes,resizable=no,width=200,height=200 ");


}


Window. Status = "I only stay a while!" ";

SetTimeout ("Erase ()", 3000);


function Erase ()

{

Window.status= "";

}

</script>



<title>javascript window demo</title>


<body >


</body>



Case two: windowdemo2.html


<s cript language= "Javascript" >

function scroll (SEED)

{var msg= "Welcome to Yuan Java Pulpit, forum URL: www.triworks.com.cn";

var out = "";

var c = 1;

if (Seed > 100)

{seed--;

var cmd= "Scroll (" + Seed + ")";

Timertwo=window.settimeout (cmd,100);

}

Else

if (seed <= && seed > 0)

{for (c=0; c < seed; C + +)

{out+= "";

}

out+=msg;

seed--;

var cmd= "Scroll (" + Seed + ")";

Window.status=out;

Timertwo=window.settimeout (cmd,100);

}

Else

if (seed <= 0)

{if (-seed < msg.length)

{out+=msg.substring (-seed,msg.length);

seed--;

var cmd= "Scroll (" + Seed + ")";

Window.status=out;

Timertwo=window.settimeout (cmd,100);

}

Else

{window.status= "";

Timertwo=window.settimeout ("Scroll (100)", 7);

}

}

}

Timerone=window.settimeout (' Scroll (100) ', 50);

</script>



<title>javascript window demo2</title>


<body>

<br><br><br>

-->

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.