ACC Tips & Tricks, Adobe Campaign, Marketing Automation

ACC | How to utilize OOP in ES5

Adobe Campaign Classic OOP concepts in ES5

In this blog I will be exploring object-oriented programming (OOP) and Adobe Campaign Classic in ES5. As you may already know, Adobe Campaign Classic relies on ES5, the version of JavaScript specifically used by the platform.

In ES5, there are a few limitations in terms of what you cannot do compared to newer versions of JavaScript (ES6 and beyond) when it comes to object-oriented programming (OOP). Here are a few aspects that may be limited in ES5:

  1. Class Syntax: ES5 does not have native support for the class syntax introduced in ES6. Instead, constructor functions and prototypes are commonly used to define objects and their behaviors.
  2. Inheritance with class: ES5 does not have the extends keyword for class inheritance. Instead, prototype-based inheritance is used, which involves manually linking objects through their prototype chains.
  3. Private Members: ES5 lacks built-in support for defining truly private members within objects. While you can emulate privacy using closures and naming conventions (like prefixing with an underscore), they are not enforced or restricted by the language itself.
  4. Getters and Setters: ES5 does not have explicit getter and setter syntax like get and set in ES6. Instead, you need to define getter and setter methods manually within the object’s prototype.
  5. Arrow Functions: Arrow functions, introduced in ES6, have a more concise syntax and lexical this binding. In ES5, regular functions are used, which may require extra precautions for proper this context handling.
  6. Iterators and Generators: ES5 does not have built-in support for iterators and generators, which are useful for iterating over collections or creating custom iterable objects.

When exploring OOP examples in ES5 while browsing the internet, I have come across numerous implementations. Since ES5 lacks native support for the class syntax introduced in ES6, constructor functions and prototypes are widely utilized to define objects and their behaviors.

Based on the examples I’ve observed, I have developed my own implementation that addresses a crucial aspect that was missing in those solutions: private methods. Let me share my implementation with you

var MyClass = function () {
  // Public properties
  this.a = 'some public property value';
  this.b = 'another public property value';

  // Private property
  var c = 'private property';

  // Private method
  var privateMethod = function() {
    logInfo('This is a private method.');
    logInfo('Accessing a:', this.a);
    logInfo('Accessing b:', this.b);
    logInfo('Accessing c:', c); // Print the private property c
    // Add your private method implementation here

  // Public method
  this.publicMethod = function() {
    logInfo('This is a public method.');;

//extend MyClass
MyClass.prototype.function = extensionFunction (){
	logInfo("YAY, i'm something like extension method")

var a = new MyClass();
  1. The MyClass constructor function is defined. When invoked with the new keyword, it creates instances of MyClass objects.
  2. Inside the constructor function, public properties a and b are defined and assigned values. These properties are accessible from outside the object and can be accessed and modified.
  3. The variable c is declared within the constructor function, but without using this. This makes it a private property because it is not exposed as a property of the object. It is only accessible within the constructor function itself.
  4. The privateMethod function is defined within the constructor function. It is a private method because it is only accessible within the constructor function and cannot be accessed directly from outside the object.
  5. The publicMethod function is assigned to the object’s prototype. It is a public method that can be accessed from outside the object. Inside publicMethod, the private method privateMethod is invoked using call(this) to ensure it is executed in the context of the current object.
  6. Extension of original class functionality with use of Prototype methods.
  7. An instance of MyClass is created using the new keyword and assigned to the variable a.
  8. Finally, the publicMethod of the a object is called using a.publicMethod().
06/26/2023 10:28:34 AM	js	This is a public method.
06/26/2023 10:28:34 AM	js	This is a private method.
06/26/2023 10:28:34 AM	js	Accessing a: some public property value
06/26/2023 10:28:34 AM	js	Accessing b: another public property value
06/26/2023 10:28:34 AM	js	Accessing c: private property
06/26/2023 10:28:34 AM	js	YAY, i'm something like extension method

You might have noticed that to call a private method I use predefined JavaScript method – .call(). This method in JavaScript is used to invoke a function and explicitly specify the value of this within that function. It allows you to control the context in which the function is executed.

The .call() method takes two or more arguments:

  • The first argument specifies the value to be set as this within the function.
  • The subsequent arguments (optional) represent the arguments to be passed to the function.

In the context of the code you provided (, .call(this) is used to invoke the privateMethod function with the value of this set to the current object.

When .call(this) is used, it ensures that the privateMethod function is executed in the context of the current object (this). This allows privateMethod to access and manipulate the properties and methods of the object.

Oh hi there 👋
I have a FREE e-book for you.

Sign up now to get an in-depth analysis of Adobe and Salesforce Marketing Clouds!

We don’t spam! Read our privacy policy for more info.

#JavaScript #programming
Marcel Szimonisz
Marcel Szimonisz
MarTech consultant As a marketing automation consultant, I specialize in solving problems, automating processes, and driving innovation in my clients' marketing platforms.

I hold certifications in Adobe Campaign v6 (3x certified) and Salesforce Marketing Cloud (5x certified).

Additionally, I serve as a community advisor for Adobe Campaign, offering expert insights and guidance.

In addition to my professional pursuits, I also enjoy exploring various programming languages, CMSs, and frameworks, further enhancing my technical expertise and staying at the forefront of industry advancements.
Take a look at our subscription offering in case you are looking for a Marketing Automation Consultant.

Leave a comment

Your email address will not be published. Required fields are marked *

Similar posts that you may find useful

SFMC tips and tricks
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

SFMC TIP | Google Analytics Integration 1

less than a minute read

When you integrate with Google Analytics, marketing cloud will add tags to all your links. When this happens, all dynamic links will be broken. Links that are defined programmatically as variable, field or attribute with GA integrated will look as if the tracking link also appends google analytics tags. This will make such link not … Read more

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

SFMC TIP | Journey validation fails for no reason

less than a minute read

There is an error with starting the journey, specifically related to the email template, but it gives you no explanation whatsoever. I’m sure there can be many problems with the template that prevent the journey from being started. One of the problems I have experienced most recently is that the template has not been approved. … Read more

Continue reading
SFMC tips and tricks
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

SFMC TIP | Error updating filter

less than a minute read

If you’re using Email Studio in Salesforce Marketing Cloud and receive an ‘Error: updating filter’ message when creating a new Data Extension, it’s likely because the name you’ve chosen already exists. This error message can be misleading, but a simple solution is to rename the Data Extension with a more unique identifier. Make sure to … Read more

Continue reading
Adobe Campaign on Debian linux
Adobe Campaign, Marketing Automation

ACC | Installing Adobe Campaign Classic on Debian

15 minutes read

Psst! Listen up, fellow campaigners! Did you know that you can actually install Adobe Campaign Classic locally and it won’t cost you a penny? Of course, you won’t be able to run actual marketing campaigns with it, but you can use it as your personal development playground. It’s like having a sandbox, but for grown-ups. … Read more

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

SFMC TIP | HTTP post content type encoding

1 minute read

Recently, while working with the double opt-in process that employs an API to trigger messages, I encountered an issue where Latin characters were not captured correctly in the triggered send data extension. I have found that the SFMC HTTPPost uses, by default, WindowsCodePage 1252 encoding, which can cause issues with accented characters such as ž, … Read more

Continue reading