js中的this & var, function & object, prototype & apply

以下只给出几个实例。

=========================

<html>
<head>  
    <script type="text/javascript"> 
function Login(){
     this.id1 = "你能取得的值";
     var  id2 = "你还想要的值";
     this.$log = function(__){
          __.$ = function(IdName){
         return eval(IdName);
      }
     }
}
 
console.log(new Login().id1); //你能取得的值
 
var obj = {};
new Login().$log(obj);
console.log(obj.$("id2"));    //你还想要的值


console.log(function doLogin2(obj){
      new Login().$log(obj);
      return new Login().id1 + " and " + obj.$("id2")
}({}))


    </script>
    <title></title>
</head>
<body>
<pre>
//http://bbs.csdn.net/topics/310099388 
</pre>
</body>
</html>

========================= 

<html>
<head>  
    <script type="text/javascript"> 

var e=function(m,n){return m+n+a};

        function fa() {
this.a=12;
this.d= e(2,3);
this.b=function(x){
c(x);
}
function c(x) { 
console.log(" this is from c:"+x);
console.log(" this is from c:"+this.d);
}
b(a);
}
 
fa(); 
console.log(" a:"+a); //????

    </script>
    <title></title>
</head>
<body>
<pre> 
</pre>
</body>
</html>

=========================

<html>
<head>  
    <script type="text/javascript"> 
var Class = { 
    create: function() { 
        return function() { 
this.initialize.apply(this, arguments); 
        } 
    } 

//   console.log("Class:"+Class);
var Login = Class.create();
//   console.log("Login:"+Login);
Login.prototype = {
initialize: function() { }, 
    id1:11, 
    id2:22 
}
 
 
function doLogin2 (){
   var login = new Login();
   login.id3=33;
   console.log(login.id1);
   console.log(login.id2);
   console.log(login.id3);
}
//   console.log("doLogin2:"+doLogin2);
 
doLogin2();
    </script>
    <title></title>
</head>
<body>
<pre>  
//http://bbs.csdn.net/topics/310099388 
</pre>
</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值