내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Explain this strange JavaScript Class declaration in core lib

Avatar

Level 3

Hello,

 

I am trying to understand how AEM's core library works, with as example this `EditorKernel.js` file in the CRXDE located at "/libs/clientlibs/granite/richtext/core/js/EditorKernel.js".

 

As you can see in its Class declaration syntax below, it is not how we normally declare JavaScript classes. It looks like it is using MooTools (https://mootools.net/core) by passing an object into a class function?

CUI.rte.EditorKernel = new Class({
    //...
});

 

However, I am not able to find anywhere that references MooTools as a dependency, not in CRXDE nor the Sources tab of the Chrome inspector.

 

Could someone help me understand:

  1. Where is the MooTools dependency referenced?
  2. If it is not using MooTools, then how to explain the non-standard javascript syntax?

 

Thanks,

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Employee

Hi @sean12341 

 

The syntax you see here totally aligns with JS standard. It is just that the name "Class" that makes the whole thing confusing. 

Now check Js file in libs which is /libs/clientlibs/granite/richtext/base/Class.js.

 

Here, Class  is being defined as JS Object which is then declared to be a function and takes one parameter which it expects to be js object. Check lines in js file mentioned:

var Class, Exception;
(function() {
    var e = function(a) {
        var b = a.bind(this);
        b._methodName = a._methodName;
        return this[b._methodName] = b
    }
      , a = function(a) {
        a.extend = this;
        return new Class(a)
    };
    Class = function(b) {
        b = b || {};

 

Now, if you check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new "new" operator can then be used on any function to declare further objects as explained in documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new like


car1 = new Car('Eagle', 'Talon TSi', 1993);

 

Hope it explains.

Thanks,

Nupur

 

원본 게시물의 솔루션 보기

1 답변 개

Avatar

정확한 답변 작성자:
Employee

Hi @sean12341 

 

The syntax you see here totally aligns with JS standard. It is just that the name "Class" that makes the whole thing confusing. 

Now check Js file in libs which is /libs/clientlibs/granite/richtext/base/Class.js.

 

Here, Class  is being defined as JS Object which is then declared to be a function and takes one parameter which it expects to be js object. Check lines in js file mentioned:

var Class, Exception;
(function() {
    var e = function(a) {
        var b = a.bind(this);
        b._methodName = a._methodName;
        return this[b._methodName] = b
    }
      , a = function(a) {
        a.extend = this;
        return new Class(a)
    };
    Class = function(b) {
        b = b || {};

 

Now, if you check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new "new" operator can then be used on any function to declare further objects as explained in documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new like


car1 = new Car('Eagle', 'Talon TSi', 1993);

 

Hope it explains.

Thanks,

Nupur