开发者

OOP framework for js and jquery [closed]

开发者 https://www.devze.com 2023-03-14 02:59 出处:网络
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 3 years ago.

Improve this question

I am developing a web application. The application is becoming quite complex, to the extant I decided I've got to introduce some oop concepts.

The original js oop just isn't native enough for me (I am a .net developer), and its inheritance is awful. I came across http://moo4开发者_如何学Goq.com/ which looks promising, but seems to be rather new. This is quite a risk for me.

What other oops frameworks are there, to enhance my jquery / js development?

EDIT 1

I am not looking for a framework to substitute jquery, I am looking for a framework to extend it.

thank you


Backbone.js adds some conecpts of OOP to javascript that might help you. It is very complementary to jQuery and adds on its abilities.


You might want to consider Knockout for simplifing your UI implementation with the MVVM design pattern.


check out this project:

https://github.com/pylover/joop

  • Cross-Browser
  • Javascript prototype
  • Inheritance hierarchy
  • Multiple inheritance & mixins
  • Singleton pattern
  • Static members

Example:

Namespace('bmw.Car');

Class('bmw.Car', {
    maxSpeed : 200,                         // Prototype member
    __init__ : function(color,cylindres) {  // Constructor
        this.speed = 0;                     // Instance Member 
        this.color = color;
        this.cylindres = cylindres == undefined ? 4 : cylindres; 
    },
    isRunning : function() {                // Method
        return this.speed > 0;
    },
    run : function(speed) {
        this.speed = speed;
    }
}).StaticMembers({
    doors: 4,                               // Static field
    createSuperClass: function(){           // Static method
        return new this('gold',12);
    }
});


Check http://ejohn.org/blog/simple-javascript-inheritance/ OOP Approach form John Resig (creator of JQuery)


The best OO framework at the moment as far as my research tells me is http://prototypejs.org. It has a lot in common with jQuery but goes beyond jQuery in that it is also a JavaScript object oriented framework.

I disagree with the above post about light weight OO in JavaScript. When you code a big object you don't want to get stuck with lots of low level technical OO details - you just want to write tons of classes and know that you are on rock solid ground and prototype will do that for you.

What does prototype give you? a clean OO framwork that supports inheritance, constructors, mixins, clean way to call superclass methods, special class members, adding methods on the fly and much more.

Prototype can be used on the same page as jQuery. This requires the correct order of importing the two libraries and not much more. It is very small (98K minified).


Javascript has a very elegant way to work with objects. Be careful about using libraries to implement such basic OO features. In Javascript you can write object oriented code clean and nicely:

  • Just use literal objects
  • Forget the 'new' statement and 'prototype'
  • Write a function that builds an object and call it a 'class'

Here is an example micro-framework (70 lines) that illustrates this:

https://github.com/schuttelaar/Rococo2/wiki/Getting-started

Notice that while this framework offers some DOM integration, it actually does not provide OO sugar functionality, instead it offers a 'coding style'.

Here is my own page explaining featherlight OOP in JS:

http://www.gabordemooij.com/jsoop.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号