zoukankan      html  css  js  c++  java
  • JS比较思维模型

    在这里,要分享的JS中两种思维方式:

    1)面向对象风格示例:

    function Foo(who){
                 this.me = who;
             }
             Foo.prototype.identify = function(){
                 return "I am"+this.me;
             };
             function Bar(who){
                 Foo.call(this,who);
             }
             Bar.prototype = Object.create(Foo.prototype);
             Bar.prototype.speak = function(){
                 alert("Hello,"+this.identify()+".");
             };
             var b1 = new Bar("b1");
             var b2 = new Bar("b2");
             b1.speak();
             b2.speak();

    2)对象关联风格示例:

    Foo = {
                 init:function(who){
                     this.me = who;
                 },
                 identify:function(){
                     return "I am"+this.me;
                 }
             };
             Bar = Object.create(Foo);
             Bar.speak = function(){
                 alert("Hello,"+this.identify()+".");
             };
             var b1 = Object.create(Bar);
             b1.init("b1");
             var b2 = Object.create(Bar);
             b2.init("b2");
             b1.speak();
             b2.speak();
  • 相关阅读:
    触发器
    自定义变量
    系统变量
    Interval 计时器
    Ajax 之 DWR
    cssTest
    Ajax之XMLHttpRequst对象
    添加页面元素
    jquery 基础
    jQuery 自定义动画效果
  • 原文地址:https://www.cnblogs.com/wccc/p/6744561.html
Copyright © 2011-2022 走看看