javascript Öеļ̳з½·¨
1.¿ÉÒÔͨ¹ýprototypeÊôÐÔ£¬ÊµÏּ̳з½·¨µÄ·½Ê½£¬ÕâÖÖ·½Ê½¾ÍÊÇjavaÓïÑÔÖм̳еı任ÐÎʽ¡£
// Create the constructor for a Person object
function Person( name ) {
this.name = name;
}
// Add a new method to the Person object
Person.prototype.getName = function() {
return this.name;
};
Person.prototype.setName = function(name) {
this.name = name;
};
// Create a new User object constructor
function User( name, password ) {
// Notice that this does not support graceful overloading/inheritance
// e.g. being able to call the super class constructor
this.name = name;
this.password = password;
};
// The User object inherits all of the Person object's methods
User.prototype = new Person();
2.ͨ¹ý×Ô¼ºÐ´¼Ì³Ðº¯Êý£¬ÊµÏּ̳У¬ÏÂÃæÕâ¶Î´úÂëÒ²ºÜºÃ£¬ÖµµÃÒ»¿´
// A simple helper that allows you to bind new functions to the
// prototype of an object
Function.prototype.method = function(name, func) {
this.prototype[name] = func;
return this;
};
// A (rather complex) function that allows you to gracefully inherit
// functions from other objects and be able to still call the 'parent'
// object's function
Function.method('inherits', function(parent) {
// Keep track of how many parent-levels deep we are
var depth = 0;
// Inherit the parent's methods
var proto = this.prototype = new parent();
// Create a new 'priveledged' function called 'uber', that when called
// executes any function that has been written over in the inheritance
this.method('uber', function uber(name) {
var func; // The function to be execute
var ret; // The return value of the function
&n
Ïà¹ØÎĵµ£º
ÔÚjsÖУ¬Ã¿¸ö¶ÔÏó¶¼ÓÐÒ»¸öprototypeÊôÐÔ£º·µ»Ø¶ÔÏóÀàÐÍÔÐ͵ÄÒýÓ᣺ÜÞÖ¿Ú£¡Ï°Óï“ÒÀºù«»Æ°”£¬ÕâÀïµÄºù«¾ÍÊÇÔÐÍ£¬ÄÇô“Æ°.prototype” ·µ»ØµÄ¾ÍÊǺù«£¬»òÕß“Æ°.prototype= new ºù«()”¡£
prototypeµÄÓÃ;£º
¼Ì³Ð
ÓÐÒ»¸ö¶ÔÏó££×ÓÀࣺ
function ×ÓÀà() {
this.lastname = ......
¶þÊ®¡¢Bookmarklet
1¡¢Ê²Ã´ÊÇBookmarklet£¿£¨What's a Bookmarklet?£©
Q£ºÊ²Ã´ÊÇBookmarklet£¿
A£ºBookmarkletÊÇÕû¸ö¶¼±»°üº¬ÔÚ³¬Á´½ÓURLÖеÄһС¶ÎJavaScript³ÌÐò¡££¨JavaScript URL¾ÍÊÇÕâ¸öÑù×Ó£º<a href="javascript:the code goes here">¡££©¶àÊýä¯ÀÀÆ÷ÔÊÐíÓû§Ìí¼ÓÕâЩJavaScript URLÊéÇ©£¬¾ÍÏñÌí¼ÓÆäËû³¬Á´½ ......
Ô´´úÂëÈçÏ£º
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ÑéÖ¤ÓÊÏäµØÖ·ºÏ·¨ÐÔ</title>
<sc ......
//°ÑÊý¾ÝдÈëÊý¾Ý¿â
function
res(){
//»ñÈ¡ÊäÈëÖµ(mynameºÍmymailÊÇÁ½¸öÎı¾¿òµÄid)
var
uname = document.getElementById("myname"
).value;
var
umail = document.getElementById("mymail"
).value;
......
±ê×¼µÄWeb ×é³ÉÓ¦¸Ã°üÀ¨3 ²¿·Ö£º½á¹¹¡¢ÐÐΪºÍ±íÏÖ¡£ÕâÖÖ˼Ïë×îÔçÔÚ΢ÈíÉè¼ÆµÄ
DHTMLÄ£ÐÍÖгõ²½Ìá³öÀ´£¬µ«ÊǺܲ»¹æ·¶£¬Ò²²»³Éϵͳ¡£ºóÀ´£¬W3C£¨World Wide Web
Consortium£¬ÍòάÍøÁªÃË£©×éÖ¯¹æ·¶ÁËWeb µÄ¹¹³É¡£¸ù¾ÝW3C Öƶ©µÄ±ê×¼£¬Web ±ê×¼²»
ÊÇijһ¸ö±ê×¼£¬¶øÊÇһϵÁбê×¼µÄ¼¯ºÏ¡£ÍêÕûµÄWeb Ó¦¸ÃÓÉÒÔÏÂ3 ²¿·Ö×é³É£º
½á ......