7

I saw this code inside a web application and wanted to understand it better (so as to be able to create this sort of structures myself), but I am not sure what kind of JavaScript this is.

What I mean is, is the Class.create() syntax part of "out of the box" JavaScript or part of some library that is embedded in this web application?

enter image description here

x457812
  • 209
  • 3
  • 9
  • 6
    It's a [part of PrototypeJS API](http://api.prototypejs.org/language/Class/create/). – raina77ow Mar 05 '15 at 22:11
  • As far as I understand the web application is ServiceNow. You can find the source code here: "Script Includes -> PrototypeServer" – filler36 Feb 21 '22 at 14:17

3 Answers3

6

Class (as in window.Class) is not part of the JavaScript standard. Thus any method on it, including Class.create, is not part of standard JavaScript.

Open up a vanilla console and do: typeof Class.

The result is "undefined".


There exists Prototype and other "Class" variations - see which library is loaded.

user2864740
  • 60,010
  • 15
  • 145
  • 220
1

So Class in this example is utility that is defined in one of the referenced script libraries. It is basically an abstraction on top of the javascript Object, which will allow you to use certain built-in functionality like if you inherit from it and define your "class" you will have a _super method which allows you to call a base class method definition.

Object.create()

Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
-1

Here's a the very best tutorial i found on the net about oop on js

I hope you understand bits of german. So ive learned objective js.

LuckyLikey
  • 3,504
  • 1
  • 31
  • 54
  • Another article that get's inheritance wrong. Sets Child prototype with an instance of Parent and does not re use Parent constructor by doing `Parent.call(this,args)` in Child constructor. Now your Child instances end up with having instance specific Parent members on their prototype. Sample code works by accident and not by design because Parent doesn't have mutable instance specific members. http://stackoverflow.com/a/16063711/1641941 – HMR Mar 06 '15 at 01:32