• js比较洋气的写法


    案例一:使用js的构造方法生成js对象、给该对象赋属性值或function

    案例二:使用json的代码风格,完成同样的功能。

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<script type="text/javascript" src="js/jquery-1.8.3.js" ></script>
    		<script type="text/javascript">
    			
    			//案例一
    			function run1(name,age,sayHello){
    				this.run1_name = name;
    				this.run1_age = age;
    				this.run1_init = sayHello;
    			}
    			var ex1 = new run1("pecool",27,function(){
    				alert("hi hello haha");
    			})
    			alert("案例一:"+ex1.run1_age);
    			alert("案例一:"+ex1.run1_name);
    			ex1.run1_init();
    			
    			
    			//案例二
    			var run2 =
    			{
    				name : undefined,
    				age : undefined,
    				sayHello : undefined
    			}
    			
    			run2.name = "pecool";
    			run2.age = "27";
    			run2.sayHello = function(){
    				alert("say hello!!");
    			}
    			alert("案例二:"+run2.name);
    			alert("案例二:"+run2.age);
    			run2.sayHello();
    			
    			
    		</script>
    		<title></title>
    	</head>
    	<body>
    		
    	</body>
    </html>
    

      

    Best Regards
  • 相关阅读:
    【BZOJ2067】[Poi2004]SZN
    BZOJ4675
    [bzoj3522][bzoj4543][POI2014]HOTEL
    bzoj2969矩形粉刷
    bzoj2969矩形粉刷
    1419: Red is good
    【BZOJ2698】染色
    BZOJ5084[hashit]
    [WC2014]紫荆花之恋
    齐次常系数递推关系式
  • 原文地址:https://www.cnblogs.com/pecool/p/10247576.html
Copyright © 2020-2023  润新知