JavaScript基础知识2
	
    
    
	玩PHP、Delphi、Java基本上都有对象,习惯这种思路后上手任何语言都想靠OO思路,这绝不是在赶时髦,而是把相关代码进行内聚的确可以体会到维护的方便!
在JavaScript中如何创建对象?
JavaScript是基于对象的!它也是以Object为根类,其它类继承之。在根类提供了几个方法。供继承类使用!
以下是创建对象的例子:
function testClass(name){
				this.firstname=name;  
			  }
var obj=new testClass("testName");
		  alert(obj.firstname);
使用javascript创建对象,给我的感觉,每个函数就好像是一个构造函数。对构造函数进行new ,对象自然就被创建了!
此外还可以这样创建,这种情况一般用在与第3方接口时,使用Ajax进行Request后,返回JSON,而后JS直接对JSON进行解析,访问其内的元素非常方便!
下例:
var obj={firstname:"l",lastname:"p"};
		
		  alert(obj.firstname);
    
     
	
	
    
    
	相关文档:
        
    
    Dynamic Scopes  动态作用域
    Both the with statement and the catch clause of a try-catch statement, as well as a function containing eval_r(), are all considered to be dynamic scopes. A dynamic scope is one that exists only through execution of code and therefore cannot be det ......
	
    
        
    
    Nested Members  嵌套成员
    Since object members may contain other members, it's not uncommon to see patterns such as window.location.href in JavaScript code. These nested members cause the JavaScript engine to go through the object member resolution process each time a dot is  ......
	
    
        
    
    C#代码与javaScript函数的相互调用
问:
1.如何在JavaScript访问C#函数?
2.如何在JavaScript访问C#变量?
3.如何在C#中访问JavaScript的已有变量?
4.如何在C#中访问JavaScript函数?
问题1答案如下:
javaScript函数中执行C#代码中的函数:
方法一:1、首先建立一个按钮,在后台将调用或处理的内容写入button_click中 ......
	
    
        
    
    function db()
	{		
		//活动编号
		var activeid = Request.Form("activeid");
		//用户名
		var username = Request.Form("username");
		//手机号码
		var mobile = Request.Form("mobile");		
		var conn= Server.CreateObject("ADODB.connection");
		var rs= Serve ......
	
    
        
    
    3、组合构造函数/原型方式写类,采用前面种方式继承
这种方式父类,子类的属性都挂在构造函数里,方法都挂在原型上。
/**
 * 父类Polygon:多边形
 */
function Polygon(sides) {
	this.sides = sides;
}
Polygon.prototype.setSides = function(s) {this.sides=s;}
/**
 * Triangle 三角形
 * @param {Object} b ......