js命名空间的使用

js命名空间的使用:

test.html

代码如下:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>测试命名空间</title>
    <script src="test.js" type="text/javascript" ></script>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript" ></script>
</head>
<body>
<div>
    <a href="javascript:void(0)" onclick="a.add()">测试命名空间</a>
    <div id="htmla"></div>
    <div id="htmlb"></div>
</div>


</body>
</html>

 

test.js的源码:

var   a = {

        $scope : "xxxxxx",

        add:function( ) {
            $scope = "ttttt";
            $("#htmla").html( $scope);  //输出 ttttt
            $("#htmlb").html( this.$scope);  //输出xxxxx
        } 


};

posted @ 2014-08-07 18:21  ylong52  阅读(182)  评论(0编辑  收藏  举报