javascriptдÀ෽ʽ֮Èý
È¡Ç°ÃæÁ½ÖÖµÄÓŵ㣺
a¡¢Óù¹Ô캯ÊýÀ´¶¨ÒåÀàÊôÐÔ£¨×ֶΣ©
b¡¢ÓÃÔÐÍ·½Ê½À´¶¨ÒåÀàµÄ·½·¨¡£
¾ÍÓÐÁ˵ÚÈýÖÖ·½Ê½¡£ÕâÖÖ·½Ê½Ã²ËƲÉÓõÄÈ˽϶ࡣ
3¡¢×ۺϹ¹Ô캯Êý/ÔÐÍ
/**
* PersonÀࣺ¶¨ÒåÒ»¸öÈË£¬ÓиöÊôÐÔname£¬ºÍÒ»¸ögetName·½·¨
* @param {String} name
*/
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
ÕâÑù£¬¼´¿Éͨ¹ý¹¹Ô캯Êý¹¹Ô첻ͬnameµÄÈË£¬¶ÔÏóʵÀýÒ²¶¼¹²ÏígetName·½·¨£¬²»»áÔì³ÉÄÚ´æÀË·Ñ¡£
µ«ËƺõÕâÑùµÄ´úÂë·ç¸ñËƺõÈÔȻûÓÐjavaµÄÀàÄÇô½ô´Õ£¬°ÑÊôÐÔ£¬¹¹Ôì·½·¨£¨º¯Êý£©£¬·½·¨¶¼°üÔÚ´óÀ¨ºÅÄÚ¡£
public class Person {
//ÊôÐÔ£¨×ֶΣ©
String name;
//¹¹Ôì·½·¨£¨º¯Êý£©
Person(String name) {
this.name = name;
}
//·½·¨
String getName() {
return this.name;
}
}
ΪÁËÈÃjs´úÂë·ç¸ñ¸ü½ô´Õ£¬°Ñ¹ÒÔÚprototypeµÄ·½·¨´úÂëÒƵ½function PersonµÄ´óÀ¨ºÅÄÚ¡£
function Person(name) {
this.name = name;
Person.prototype.getName = function() {
return this.name;
}
}
ËƺõºÜÉñÆ棬»¹ÄÜÕâôд°¡£¡ÑéÖ¤Ò»ÏÂ
var p1 = new Person("Jack");
var p2 = new Person("Tom");
console.log(p1.getName());//Jack
console.log(p2.getName());//Tom
ûÓб¨´í£¬¿ØÖÆ̨ҲÕýÈ·Êä³öÁË¡£ËµÃ÷¿ÉÒÔÕâôд£¬ºÇºÇ¡£
àÅ£¬ËƺõºÜÍêÃÀ¡£
a ¡¢¿ÉÒÔͨ¹ý´«²Î¹¹Ôì¶ÔÏóʵÀý
b ¡¢¶ÔÏóʵÀý¶¼¹²Ïíͬһ·Ý·½·¨²»Ôì³ÉÄÚ´æÀË·Ñ
c ¡¢´úÂë·ç¸ñÒ²±È½Ï½ô´Õ
µ«Ã¿´ÎnewÒ»¸ö¶ÔÏóµÄʱºò¶¼»áÖ´ÐÐ
Person.prototype.getName = function() {
return this.name;
}
Ôì³ÉÁ˲»±ØÒªµÄÖظ´µÄÔËËã¡£ÒòΪgetName·½·¨¹ÒÔÚprototypeÉÏÖ»ÐèÖ´ÐÐÒ»´Î¼´¿É¡£Ö»ÐèÉÔ΢¸ÄÔìÏ£º
function Person(name) {
this.name = name;
if(Person._init==undefined) {
alert("ÎÒÖ»Ö´ÐÐÒ»´Î£¡");
Person.prototype.getName = function() {
return this.name;
}
Person._init = 1;
}
}
newÁ½¸ö¶ÔÏó£¬
var p1 = new Person("Andy");//µÚÒ»´Înew»áµ¯³ö'ÎÒÖ»Ö´ÐÐÒ»´Î£¡'
var p2 = new Person("Lily");//ÒÔºónewµÄ¶ÔÏó²»»áÔÙÖ´ÐÐÁË
Ïà¹ØÎĵµ£º
<!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>
<meta http-equiv="Content-Type" content="text/html; ......
ȺÀïÌÖÂÛ¹ýµÄÌâÄ¿£¬·ÖÏíһϡ£
function test(){
var m=n=1;
alert(m);
}
alert(n);
//ÒòΪtestº¯ÊýûÓÐÖ´ÐУ¬³Ì¶È¿ØÖÆÁ÷²»ÄܽøÈë½øÐнâÎö£¬ÀïÃæµÄ¶«Î÷¶ÔÍâÃæ²»¿É¼û£¬Òò´Ë±¨´í
function test(){
var m=n=1;
alert(m);
}
test();
alert(n);
//µ±testÖ´Ðкó£¬Í ......
¼ÙÈçä¯ÀÀÆ÷À뿪ÁËJavaScript
¼ÙÈçä¯ÀÀÆ÷À뿪ÁË JavaScript£¬ÄÇô»¥ÁªÍøÉϾø´ó¶àÊýÍøÒ³¾ÍÎÞ·¨Õ¹Ê¾¡£µ«ÊǼ¤½øµÄÖ÷ÕŲ¢·ÇÒ»ÎÞÊÇ´¦£¬ÖÁÉÙËüÄÜ·ñ´Ù½øÎÒÃǶÔÊìÊÓÎ޶õÄÊÂÎ»»Ò»¸ö½Ç¶È×ö½øÒ»²½Ë¼¿¼¡£¼ÙÈçÓÃJavaÌæ»»JavaScript£¬»áÓÐʲôºÃ´¦£¿ºÃ´¦»òÐíÓÐÈý¸ö²ãÃ棬¶ÔÓÚÊÖ»úÓ¦ÓöøÑÔ£¬ÕâЩÓŵãÓÈÆä¿É¹ó¡£
1. Ô¤ÏȱàÒ룬ʼþÏì ......
JavaScriptÖеÄJSON
JavaScriptÊÇΪÍø¾°ä¯ÀÀÆ÷×öÒ³Ãæ½Å±¾ÓïÑÔ¶øʵÏÖµÄÒ»ÖÖ±à³ÌÓïÑÔ¡£ËüÏÖÔÚ»¹±»ºÜ¶àÈËÎó½âÊÇjavaµÄ×Ó¼¯¡£ËüÊÇÒ»ÖÖ¾ßÓÐÀàCÓï·¨ºÍÈõ¶ÔÏóµÄģʽÓïÑÔ¡£JavaScriptÍêÈ«×ñÊØECMAScriptÓïÑÔ˵Ã÷ÊéµÚÈý°æ¡£
JSONÊÇJavaScript¶ÔÏóÎÄ×ּǺŵÄ×Ó¼¯¡£ÓÉÓÚJSONÊÇJavaSriptµÄ×Ó¼¯£¬ËùÒÔÔÚJavaScriptÀ ......
1¡¢IsStartupScriptRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁËÆôÓýű¾¡£
2¡¢IsClientScriptBlockRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁË¿Í»§¶Ë½Å±¾¿é¡£
3¡¢IsClientScriptIncludeRegistered£º¶ÔÏóÊÇ·ñ×¢²áÁË¿Í»§¶Ë½Å±¾°üº¬¡£
µÚÒ»¸öÀý×Ó£º
string info = "<script>alert('ÄãºÃÂð£¿');</script>";
//ÅжÏʼþÊÇ·ñ±»×¢²á£¬Ð´ÈëÇ ......