ÃæÏò¶ÔÏóµÄÓïÑÔ¶àÊý¶¼Ö§³Ö¼Ì³Ð£¬¼Ì³Ð×îÖØÒªµÄÓŵã¾ÍÊÇ´úÂ븴Ó㬴Ӷø¹¹½¨´óÐÍÈí¼þϵͳ¡£Èç¹ûÒ»¸öÀàÄܹ»ÖØÓÃÁíÒ»¸öÀàµÄÊôÐԺͻò·½·¨£¬¾Í³Æ֮Ϊ¼Ì³Ð¡£
´ÓÕâ¸ö½Ç¶ÈÀ´¿´¿´jsµÄ¼Ì³Ð·½Ê½¡£jsÖм̳з½Ê½ÓëдÀ෽ʽϢϢÏà¹Ø¡£²»Í¬µÄдÀ෽ʽÔì³É²»Í¬µÄ¼Ì³Ð·½Ê½¡£¸÷ÖÖÁ÷ÐÐjs¿â¼Ì³Ð·½Ê½Ò²¸÷²»Ïàͬ¡£´Ó×î¼òµ¥µÄ
¸´ÓÿªÊ¼¡£
1¡¢¹¹Ô캯ÊýдÀ࣬ͨ¹ý·½·¨µ÷Óø´ÖƸ¸ÀàÊôÐÔ¸ø×ÓÀà
ʵÏּ̳Ð
ÕâÀ︸À࣬×ÓÀ඼Óù¹Ô캯Êý·½Ê½Ð´£¬²»ÓÃÔÐÍ¡£×ÓÀàµ÷Óø¸ÀຯÊýÀ´¸´ÖƸ¸ÀàµÄÊôÐÔ¡£
/**
* ¸¸ÀàPolygon:¶à±ßÐÎ
* @param {Object} sides
*/
function Polygon(sides) {
this.sides = sides;
this.setSides = function(s) {this.sides=s;}
}
/**
* ×ÓÀàTriangle:Èý½ÇÐÎ
*/
function Triangle() {
this.tempfun = Polygon;//¸¸ÀàÒýÓø³Öµ¸ø×ÓÀàµÄÒ»¸öÊôÐÔtempfun
this.tempfun(3);//µ÷ÓÃ
delete this.tempfun;//ɾ³ý¸ÃÊôÐÔ
this.getArea = function(){};
}
//new¸ö¶ÔÏó
var tri = new Triangle();
console.log(tri.sides);//¼Ì³ÐµÄÊôÐÔ
console.log(tri.setSides);//¼Ì³ÐµÄ·½·¨
console.log(tri.getArea);//×ÔÓеķ½·¨
//ȱµãÊǶÔÓÚTriangleµÄʵÀý¶ÔÏóÓÃinstanceo ......
2¡¢ÔÐÍ·½Ê½Ð´À࣬ÔÐÍ·½Ê½¼Ì³Ð
core js×ÔÉíµÄ¶ÔÏóϵͳ¾ÍÊDzÉÓÃÔÐÍ·½Ê½(prototype based)¼Ì³ÐµÄ¡£»òÕß˵core
jsûÓвÉÓó£¼ûµÄÀà¼Ì³Ð(class
based)ϵͳ£¬¶øÊÇʹÓÃÔÐͼ̳ÐÀ´ÊµÏÖ×Ô¼ºµÄ¶ÔÏóϵͳ¡£¹¤×÷ÖÐÎÒÃÇÒ²¿ÉÒÔÓÃÔÐÍ·½Ê½À´ÊµÏּ̳У¬´úÂ븴ÓÃÒÔ¹¹½¨×Ô¼ºµÄ¹¦ÄÜÄ£¿é¡£
/**
* ¸¸ÀàPolygon:¶à±ßÐÎ
*
*/
function Polygon() {}
Polygon.prototype.sides = 0;
Polygon.prototype.setSides = function(s) {this.sides=s;}
/**
* ×ÓÀàTriangle:Èý½ÇÐÎ
*/
function Triangle() {}
Triangle.prototype = new Polygon();//¹Ø¼üÒ»¾ä
Triangle.prototype.getArea = function(){}
//new¸ö¶ÔÏó
var tri = new Triangle();
console.log(tri.sides);//¼Ì³ÐµÄÊôÐÔ
console.log(tri.setSides);//¼Ì³ÐµÄ·½·¨
console.log(tri.getArea);//×ÔÓз½·¨
//instanceof²âÊÔ
console.log(tri instanceof Triangle);//true£¬±íÃ÷¸Ã¶ÔÏóÊÇÈý½ÇÐÎ
console.log(tri instanceof Polygon);//true£¬±íÃ÷Èý½ÇÐÎÒ²ÊǶà±ßÐÎ
ËäÈ»´ÓÊä³ö¿ÉÒÔ¿´³ö×ÓÀà¼Ì³ÐÁ˸¸ÀàPolygonµÄÊôÐÔsidesºÍ·½·¨setSides£¬µ«sidesÊÇ0£¬Ôõô»áÊÇÈý½ÇÐÎÄØ¡£»¹µÃµ÷ÓÃÏÂ
tri.setSides(3)ʹ֮³ÉΪÈý½ÇÐΡ£ÕâÑ ......
JavaScriptʼþ´óÈ«
click() ¶ÔÏó.click() ʹ¶ÔÏó±»µã»÷¡£
closed ¶ÔÏó.closed ¶ÔÏó´°¿ÚÊÇ·ñÒѹرÕtrue/false
clearTimeout(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetTimeout¶ÔÏó
clearInterval(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetInterval¶ÔÏó
confirm("ÌáʾÐÅÏ¢") µ¯³öÈ·ÈÏ¿ò£¬È·¶¨·µ»ØtrueÈ¡Ïû·µ»Øfalse
cursor:Ñùʽ ¸ü¸ÄÊó±êÑùʽ hand crosshair text wait help default auto
e/s/w/n-resize
event.clientX ·µ»Ø×îºóÒ»´Îµã»÷Êó±êX×ø±êÖµ£»
event.clientY ·µ»Ø×îºóÒ»´Îµã»÷Êó±êY×ø±êÖµ£»
event.offsetX ·µ»Øµ±Ç°Êó±êÐüÍ£X×ø±êÖµ
event.offsetY ·µ»Øµ±Ç°Êó±êÐüÍ£Y×ø±êÖµ
document.write(document.lastModified) ÍøÒ³×îºóÒ»´Î¸üÐÂʱ¼ä
document.ondblclick=x µ±Ë«»÷Êó±ê²úÉúʼþ
document.onmousedown=x µ¥»÷Êó±ê¼ü²úÉúʼþ
document.body.scrollTop; ·µ»ØºÍÉèÖõ±Ç°ÊúÏò¹ö¶¯ÌõµÄ×ø±êÖµ£¬ÐëÓ뺯ÊýÅäºÏ
,
document.body.scrollLeft; ·µ»ØºÍÉèÖõ±Ç°ºáÏò¹ö¶¯ÎñµÄ×ø±êÖµ£¬ÐëÓ뺯ÊýÅä
ºÏ£¬
document.title document.title="message"; µ±Ç°´°¿ÚµÄ±êÌâÀ¸ÎÄ×Ö
document.bgcolor document.bgcolor="ÑÕÉ«Öµ"; ¸Ä±ä´°¿Ú±³¾°ÑÕÉ ......
3¡¢×éºÏ¹¹Ô캯Êý/ÔÐÍ·½Ê½Ð´À࣬²ÉÓÃÇ°ÃæÖÖ·½Ê½¼Ì³Ð
ÕâÖÖ·½Ê½¸¸À࣬×ÓÀàµÄÊôÐÔ¶¼¹ÒÔÚ¹¹Ô캯ÊýÀ·½·¨¶¼¹ÒÔÚÔÐÍÉÏ¡£
/**
* ¸¸ÀàPolygon:¶à±ßÐÎ
*/
function Polygon(sides) {
this.sides = sides;
}
Polygon.prototype.setSides = function(s) {this.sides=s;}
/**
* Triangle Èý½ÇÐÎ
* @param {Object} base µ×
* @param {Object} height ¸ß
*/
function Triangle(base,height) {
Polygon.call(this,3);//¸´ÖƸ¸ÀàÊôÐÔ¸ø×Ô¼º
this.base = base;
this.height = height;
}
Triangle.prototype = new Polygon();//¸´ÖƸ¸Àà·½·¨¸ø×Ô¼º
Triangle.prototype.getArea = function(){ //×îºó¶¨Òå×Ô¼ºµÄ·½·¨
return this.base*this.height/2;
}
//new¸ö¶ÔÏó
var tri = new Triangle(12,4);
console.log(tri.sides);//¼Ì³ÐµÄÊôÐÔ
console.log(tri.setSides);//¼Ì³ÐµÄ·½·¨
console.log(tri.base);//×ÔÓÐÊôÐÔ
console.log(tri.height);//×ÔÓÐÊôÐÔ
console.log(tri.getArea);//×ÔÓз½·¨
//instanceof²âÊÔ£¬±íÃ÷ÕýÈ·µÄά»¤ÁË"is a"µÄ¹Øϵ
console.log(tri instanceof Triangle);//true£¬±íÃ÷¸Ã¶ÔÏóÊÇÈý½ÇÐÎ
console.log(tri instance ......
JavascriptÊý¾ÝÀàÐÍ
ÓÉÓÚjavascriptÊÇÈõÀàÐÍÓïÑÔ£¬¼´¶¨Òå±äÁ¿Ê±²»±ØÉùÃ÷ÆäÀàÐÍ
¡£µ«Õâ²¢²»Òâζ×űäÁ¿Ã»ÓÐÀàÐÍ¡£ÒòΪ¸³ÖµÊ±»á×Ô¶¯Æ¥ÅäÊý¾ÝÀàÐÍ£¡
Ä¿Ç°Óõ½µÄ»ù±¾Êý¾ÝÀàÐÍ
number
boolean
string
var i
i="test";//Õâʱi¾Í³ÉÁËstringÀàÐÍ
var i
i=4;//Õâʱi¾Í³ÉÁËnumberÀàÐÍ
³£ÓöÔÏóÀàÐÍ<object>
Date
Number
Boolean
String
RegExp
Array
Object
ÒÔÉ϶ÔÏóÀàÐ͵ÄÓ÷¨
var i;
i=new Number(123);
i.toString(2);//תΪ2½øÖÆ¡£8Ϊ8½øÖÆ
ÔÙÈ磺
var i
i=new Array(1,2,3);
......
[ת×Ô]http://article.yeeyan.org/view/mouse4x/16540
JSON±»¹«ÈÏΪä¯ÀÀÆ÷ÖÐXMLµÄºó¼ÌÕߣ¬ËüµÄÄ¿±ê½ö½öÊdzÉΪһÖÖ¼òµ¥¡¢ÓÅÑŵÄÊý¾Ý¸ñʽ£¬ÒÔ·½±ãä¯ÀÀÆ÷ºÍ·þÎñÆ÷Ö®¼äµÄÊý¾Ý½»»»¡£ÔÚÍê³ÉÕâÒ»¼òµ¥ÈÎÎñµÄ¹ý³ÌÖУ¬Ëü½«ÒýÁìÏÂÒ»´úÍòάÍø¡£
¶ÔÏó¼ò½é
¿´,Õâ¾ÍÊÇÒ»¸ö¶ÔÏó:
var myFirstObject ={};
¾¡¹Ü¿´ÆðÀ´Í¦¼òµ¥£¬È»¶øÄÇЩ»¨À¨ºÅÈ´Äܹ»¼Ç¼ÈËÀàËùËѼ¯µÄÐÅÏ¢µÄÿ¸ö±ÈÌØ£¬»òÕßÊDZíʾ³ö¼ÆËã»ú¿Æѧ¼ÒÃÇÄܹ¹Ë¼µ½µÄ×ÔӵijÌÐò.ÊÂʵÉÏ£¬Javascript±¾Éí¾ÍÊÇ´æ´¢ÔÚÄÇÑùÒ»¸ö»¨À¨ºÅ¼¯ºÏÖеģ¬°üÀ¨ËüËùÓеĻù±¾ÀàÐÍ -- ×Ö·û´®,Êý×Ö,Êý×é,ÈÕÆÚ,ÕýÔò±í´ïʽ,ËüÃǶ¼ÊǶÔÏó,¶¼ÊÇÏñÉÏÃæmyFirstObjectÄÇÑù¿ªÊ¼µÄ.
´´½¨Ò»¸öжÔÏó
¾ÉµÄ·½Ê½ÊÇʹÓÃ"new"¹Ø¼ü×Ö´´½¨Ð¶ÔÏó.
var myJSON =newObject();
ÕâÖÖ·½Ê½ÒѾ¹ýʱ,ÏÖÔÚÁ÷Ðеķ½Ê½ÊÇͨ¹ýÒ»¶Ô´óÀ¨ºÅ¶¨ÒåÒ»¸ö¿Õ¶ÔÏó...
var myJSON ={};
¶ÔÏó¼´Êý¾Ý
ÔÚJavascript¶ÔÏóµÄ×îµ×²ãÊÇÒ»ÖÖºÜÁé»îÇÒ½¡×³µÄÊý¾Ý¸ñʽ£¬±íʾΪ“Ãû/Öµ¶Ô”¡£Ò²¾ÍÊÇ˵,Ò»¸ö¶ÔÏóµÄÊôÐÔÃû--¿ÉÒÔ¿´×÷ÊÇÒÀ¸½ÔÚ¶ÔÏóÃûÉϵÄÒ»¸öÆÕͨ±äÁ¿.²¢ÇÒÕâ¸ö¶ÔÏó±£´æ×ÅÉÏÊöÃû×ÖµÄÖµ.¿´ÏÂÃæµÄÀý×Ó...
var myFirstJSON ={"firstName":"John",
......
×ܼǼÊý:2244; ×ÜÒ³Êý:374; ÿҳ6 Ìõ;
Ê×Ò³ ÉÏÒ»Ò³ [6] [7] [8] [9] 10
[11] [12] [13] [14] [15] ÏÂÒ»Ò³ βҳ