jQuery会支持OOP概念吗?

时间:2017-12-16 12:56:50

标签: jquery html oop

我在jquery中使用此代码来创建一个类并使用类变量任何人都可以帮助我在运行时如何执行此操作,这一切都没有在浏览器上显示。类名应该是通用的。

我想为简单的算术运算构建泛型类....

{% extends 'base.html.twig' %}

    {% block body %}
    <a href="#" onClick="logInWithFacebook()">test</a>
    {% endblock %}

    {% block javascripts%}

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
      logInWithFacebook = function() {
        FB.login(function(response) {
          if (response.authResponse) {
           console.log(response);
           var $data = {
                'token': response.authResponse.accessToken,
           }
          $.ajax({
          type: "POST",
          url: "http://localhost/testfb/web/app_dev.php",
          data: $data,
          context: document.body
    }).done(function(response) {
      //console.log(response);
    });
            //alert('You are logged in &amp; cookie set!');
            // Now you can redirect the user or do an AJAX request to
            // a PHP script that grabs the signed request from the cookie.
          } else {
            alert('User cancelled login or did not fully authorize.');
          }
        });
        return false;
      };
      window.fbAsyncInit = function() {
        FB.init({
          appId: '371059814596960',
          cookie: true, // This is important, it's not enabled by default
          version: 'v2.11'
        });
      };

      (function(d, s, id){
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement(s); js.id = id;
        js.src = "https://connect.facebook.net/en_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));

    </script>


    {%endblock%}

1 个答案:

答案 0 :(得分:0)

该行

simpleClassObj.testAttriute;

不执行任何操作,因为您只是编写属性的名称,而不将其分配给变量或将其回显到屏幕或控制台。

此外,您应该查找有关JS类的任何教程,因为这不是您在JS中声明类的方式。看起来应该是这样的:

var simpleClass = function() {

    this.testAttribute = "test"; // atttribute

    this.testMethod = function() //method
    {
        return this.testAttribute;
    };

 };

var simpleClassObj = new simpleClass();
alert(simpleClassObj.testMethod());