javascript µÄ scope
myhere
// JavaScript ½Å±¾£¬½âÎöÐÍÓïÑÔ
//
var ABCD = function(){
var pub = {};
var pri = {};
pri.name = "myhere";
pri.age = 23;
//var ABCDE;
pub.setName = function( newName){
pri.name = newName;
};
// ÕâÀï pub.getName ±»¸³ÖµÎªÒ»¸öº¯Êý£¬¾ÍÊǶ¨ÒåÒ»¸öº¯Êý
// Õâ¸öº¯Êý²¢Ã»ÓÐÔËÐУ¬Õâ¸öº¯ÊýÖеıäÁ¿(²»¹ÜÊÇ local »¹ÊÇ global ¶¼²»»á±»Ì滻ΪËûµÄÖµ)
// Òò´ËÕâ¸ö pri.name »¹ÊÇÒ»¸ö±äÁ¿£¬ÊǶ¯Ì¬µÄ
pub.getName = function(){
return pri.name;
}
// ÕâÀï pub.N ÊÇÒ»¸öÖµ£¬ÊǺ¯ÊýµÄ·µ»ØÖµ
// ¶øÇÒÕâ¸öÖµÊDz»»áËæ pri.name µÄ¸Ä±ä¶ø¸Ä±ä
// ÒòΪ pub.N ÊÇÄäÃûº¯ÊýÒÔ pri.name Ϊ²ÎÊýµ÷ÓÃÄäÃûº¯ÊýºóµÄ·µ»ØÖµ
// Õâ¸ö pub.N Ö»ÄÜÊdzÌÐòÔËÐе½ÕâʱµÄ pri.name Öµ
// pub.N Ò²¿ÉÒÔͨ¹ý ABCD.N À´¸Ä±ä
pub.N = function( e){
return e;
}( pri.name );
pub.setAge = function( newAge){
pri.age = newAge;
}
pub.getAge = function(){
return pri.age;
}
pub.setOK = function()
pub.setA = function( s){
ABCDE = s;
}
pub.getA = function(){
return ABCDE;
}
return pub;
}(); // Ö±½ÓÔËÐÐÄäÃûº¯Êý£¬ABCD ÊÇÄäÃûº¯ÊýµÄ·µ»ØÖµ£¬¼´ÄäÃûº¯ÊýÖÐµÄ pub
// ÔËÐе½Õâʱ²¢Ã»Óö¨Òå ABCDE£»
ABCD.setA( 'boy');
// ÔËÐе½Õâʱ¶¨Òå ABCDE£¬ËûµÄ×÷ÓÃÓòÊÇ global scope£¬Í¨¹ý window['ABCDE'] ¿ÉÒÔ»ñµÃ£¬
// ABCDE Óë pri( ÄäÃûº¯ÊýÖеÄ) µÄ×÷ÓÃÓò²»Ò»Ñù£¬pri Ö»ÓÐͨ¹ý ABCD µÄ½Ó¿Ú¿ÉÒÔ·ÃÎÊ
// Òò´Ë ABCD ÐγÉÒ»¸ö scope¡£pub Ï൱ÓÚ php ÖÐµÄ public£¬pri Ï൱ÓÚ private
//
// Èç¹ûÔÚÄäÃûº¯ÊýÖж¨Òå ABCDE£¬ÔòËûµÄ×÷ÓÃÓò¾Í²»ÊÇ global scope ÁË£¬Ëû¾ÍºÍ pri ÊÇͬһ¸ö×÷ÓÃÓòÁË£¬ÊôÓÚ local scope
//
// javascript Öеĺ¯Êý¿ÉÒÔ¸³Öµ¸ø±äÁ¿( very important !!!!)¡£
// º¯ÊýÓÐ×Ô¼ºµÄ scope
// Òò´ËÒ»¸öº¯Êý¶¨ÒåÖпÉÒÔǶÌ׺ܶຯÊý£¬¶øÆäÖеÄÿ¸öº¯ÊýÓÖÓÐ×Ô¼ºµÄ scope
// Òò´Ë¿ÉÒÔÓкܶàǶÌ×µÄ scope£»ÔÚÕâЩǶÌ×µÄ scope ÖУ¬Íâ²ãµÄ scope ÖеÄ
// ±äÁ¿ÔÚÄÚ²ã scope Öпɼû£»ÄÚ²ã scope ÖеıäÁ¿ÔÚÍâ²ã scope Öв»¿É¼û
//
var a = "a ";
var A = function(){
var pub = {};
var b = "b ";
pub.setValue = function( v){
var c = v || 'c ';
var setAge = function( v){
var d = v || 'd ';
return a + b + c + d;
}
Ïà¹ØÎĵµ£º
¸öÈËÈÏΪ×îºÃµÄ·½·¨²ÉÓõÄÊÇÕýÔò±í´ïʽ,ÕâÊÇ×îºËÐĵÄÔÀí.
Æä´Î.Õâ¸ö·½·¨Ê¹ÓÃÁËJavaScript µÄprototype ÊôÐÔ
ÆäʵÄ㲻ʹÓÃÕâ¸öÊôÐÔÒ»Ñù¿ÉÒÔÓú¯ÊýʵÏÖ.µ«ÕâÑù×öºóÓÃÆðÀ´±È½Ï·½±ã.
ÏÂÃæ¾ÍÀ´¿´¿´Õâ¸öÊôÐÔÊÇÔõôÀ´ÓõÄ.
·µ»Ø¶ÔÏóÀàÐÍÔÐ͵ÄÒýÓá£
objectName.prototype
objectName ²ÎÊýÊǶÔÏóµÄÃû³Æ¡£
˵Ã÷
ÓÃ ......
<script type="text/javas
cript">
var docEle = function() {
return document.getElementById(arguments[0]) || false;
}
function openNewDiv(_id){
var m = "mask";
if (docEle(_id)) document.body.removeChild(docEle(_i ......
·½·¨Ö÷ÒªÓÐÈýÖÖ
ת»»º¯Êý¡¢Ç¿ÖÆÀàÐÍת»»¡¢ÀûÓÃjs±äÁ¿ÈõÀàÐÍת»»¡£
1. ת»»º¯Êý
jsÌṩÁËparseInt()ºÍparseFloat()Á½¸öת»»º¯Êý¡£Ç°Õß°Ñֵת»»³ÉÕûÊý£¬ºóÕß°Ñֵת»»³É¸¡µãÊý¡£Ö»ÓжÔStringÀàÐ͵÷ÓÃÕâЩ·½·¨£¬ÕâÁ½¸öº¯Êý²ÅÄÜÕýÈ·ÔËÐУ»¶ÔÆäËûÀàÐÍ·µ»ØµÄ¶¼ÊÇNaN(Not a Number)¡£
ÔÚÅжÏ×Ö·û´®ÊÇ·ñÊÇÊý×Öֵǰ£¬parseInt()ºÍ ......
JavaScriptʱ¼ä²î¼ÆË㺯Êý
<mce:script language="javascript"><!--
Date.prototype.dateDiff = function(interval,objDate){
//Èô參數²»×ã»ò objDate ²»ÊÇÈÕÆÚÎï¼þ則»Ø傳 undefined
if(arguments.length<2||objDate.constructor!=Date) return undefined;
......
function openCheck()
{
if (!this.external)
{
app.alert("Acrobat¤Ç¤Ï実ÐФǤ¤Þ¤»¤ó");
this.closeDoc(true);
// var myDoc = event.target;
// myDoc.closeDoc(true);
}
}
openCheck();
ÐèҪעÒâµÄÊÇ:
1. ÉÏÊöµÄsourceÖ»ÄÜÔÚPDF ÓÃAcrobat Reader´ò¿ªÊ±²ÅÆð×÷ÓÃ,
ÈçÓÃIEµÈ´ò¿ªÊ±»á±¨¡¸NotSu ......