Skip to content

Using Javascript class objects #767

Answered by welpdx
dainbrump asked this question in Help
Discussion options

You must be logged in to vote

What I did is create a class and export the class in the .js file. Then, in templater, I create a new class, and refer to functions from that class.

filename.js

// filename.js
class SomeLib {
  functionOne() {new Notice("functionOne", 5000)}
  functionTwo() {new Notice("functionTwo", 5000)}
  functionThree() {new Notice("functionThree", 5000)}
  functionFour() {new Notice("functionFour", 5000)}
  functionFive() {new Notice("functionFive", 5000)}
}
module.exports = SomeLib

Template

// Templater Template
<%* 
const f = new tp.user.filename;
f.functionTwo();
%>

Demo

Hope that helps.

~Welp

Replies: 6 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by dainbrump
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@McGlear
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
question Further information is requested
5 participants
Converted from issue

This discussion was converted from issue #657 on September 01, 2022 14:30.