Good day. I set myself a goal at work - to avoid using such a framework as QOOXDOO. Of course, it is cool and cool, but, unfortunately, you need a python to compile the code (yes, to put the code together, you need a python), and it also weighs 100,500 meters.

In general, I tried to get around without loss for the current project. It turned out like.

Of the possibilities:

  1. The ability to create a class and its instances.
  2. The current types of classes that can be created are dynamic, singleton.
  3. The possibility of "mixing" methods of third-party classes (MICS).
  4. high inheritance
  5. Automatic creation of getters, setters and listing and type control for public variables.
  6. The ability to create static methods outside of static classes.
  7. oooooooooooochen small. Current flaws (to be corrected in a couple of days ... when I sleep enough):

  8. There is no possibility of inheriting singleton. (Functions are written, but the stuffing did not shove. Everything is simple)

An example of the simplest class:

// Mixin class smc.define("MTest", { // Static methds & properties static: { base: 0x100, unit: 0x200, resouce: 0x300 } }); // Mixin class smc.define("MTest2", { // Static methds & properties static: { moto: 0x100, auto: 0x200, velo: 0x300 } }); smc.define("MyFirstClass", { /* * Конструктор. Вызывается при создании нового экземпляра класса. */ construct: function (a,b) { if(a) this.setName(a); if(b) this.setMessage(b); this.helloWorld(); }, /* * Это примесь. Вы можете создать массив и указать SMC классы, * чьи свойства необходимо подмешать в текущий объект класса. * Если такие классы есть - Вы сможете вызвать их методы, из текущего экземпляра, * либо обратится к их переменным */ mixins: [ smc.MTest, smc.MTest2 ], /* * Это паблик- переменные класса. * value: Значение переменной * type: тип переменной (дефолт- любой) * event: Если при изменении значения переменной необходимо вызвать какую-либо функцию, */ properties: { name: { value: "Станислав", type: "string" }, message: { value: "Привет", type: "string", apply: "this.helloWorld" } }, /* * Список паблик функций, либо переменных * (как правило, сюда забрасываются переменные, которые не нуждаются в паблик доступе) */ members: { helloWorld: function () { alert( this.getMesage() + ", " + this.getName()); } }, static: { whatAreFuck: function () { console.log("Это простой статический метод у динамического объекта. Может вызываться без создания экземпляра класса") } } }); 

You can download it by clicking on this link :) http://download.tracking.by/smc.js

  • one
    Is there any comparison with existing micro-frameworks? - ReCoder
  • one
    Something like, but .... unfortunately, with his cross-browser compatibility he has it :( jsoop.codeplex.com - Stanislav Komar
  • 2
    and what is there to compare, it is a very narrowly oriented library. as if the author suggested to publish, and whoever wants, he himself will add =) - stasych
  • one
    Actually, the opinion of people is interesting. Perhaps there will be some new ideas for someone to make life easier :) One head is good, but 100500 will not look good on your neck, but it will be of high quality :) - Stanislav Komar
  • four
    Framework over 100 gig? Cool! - alexlz pm

2 answers 2

:) It is valid, really, nothing heavy :) But there are some nuances. 1. Immediately caught my eye with the example of the creation of the User and Admin. Almost copy-paste content of one object and the second. I think no one will argue if I say that this is a bit ugly :) Well, okay, it's a matter of taste, I have no right to say anything :)

Here, I wanted to draw attention to the phrase: "setters, getters, etc., etc. did not, because I do not consider it appropriate (it will be necessary - you can write a" class "with this functionality from which, then, to extend everything) . "

It is not necessary to expand the functionality at the expense of such Lesapedov :) There is a trick in what. Why I wondered about the implementation of setters and getters - obviously.

  1. You can easily control the types of variables (and sometimes it is very important)
  2. There is no need to write all kinds of cognitive functions for each getter and setter :) As the saying goes, “Everything has been done before us :)” ... and the size of the code is significantly reduced. :) I just have a position like this - the more you do now - the less then you will do everything :)
  • one
    In JavaScript, inheritance is implemented by copying the properties of one object into another (to be exact, copying the prototype). By the same - copying occurs once. Personally, I do not need getters and setters at all, so I did not write their implementation. And about the example - I just showed how to use it, I didn’t set a goal to write a cool example - Zowie
  • one
    By the way - in PHP this example would be slightly shorter, so I don’t see a problem in terms of "a lot of code" **** By the way, do you use __proto__ in your code, __proto__ it really work in IE? - Zowie
  • one
    There is no way to check)))) I haven't been using Windows for billions of years) BUT! Virtualka install, check, thank you))) - Stanislav Komar
  • 2
    And how about you with instanceof ? And maybe it was inattentive, but I still did not understand how to create instances of the class. **** To the same - in my version, the classes "by themselves", and not smc.className , I don’t know how to whom - but it strains me =) - Zowie
  • Sorry, but I also have everything by myself :) // We will continue to work with "Class" :) var Class = new smc.ClassName ("1", "params", {ololo: 123}); - Stanislav Komar

And what, so you can call a function?

 MyFirstClass::whatAreFuck(); 

In general, cool.

  • one
    You can, but like this: smc.MyFirstClass.whatAreFuck (); Thanks for rating) - Stanislav Komar
  • one
    object.mixins? object.mixins: null == object.mixins || null - Oleg
  • 2
    MyFirstClass.whatAreFuck() - that’s how it would be cooler. - Oleg
  • gygy, and how do they write jQuery ("# ​​ololo")? :) Here is the jQuery label that doesn’t bother anyone :) And mine ... 3 letters (and not obscene) is not like :( - Stanislav Komar
  • one
    Regarding jquery - it was about the amount of functionality, IMHO the namespace in your case does not make sense, and only muslin eyes. Besides, I don’t understand why keep all classes? The user already creates a variable and you have a "class" return. Ie: var someLolClass = smc.define (/ * params here * /); someLolClass is so "class", so why keep it in smc? Or is there a logic behind this? If so, you would have written it this way; in general, according to your answers, the impression was that when you wrote, you didn’t understand what you were doing. And now you don’t really understand what they want from you - Zowie