PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 24, 2022

[FIXED] How do I export a function from a module for a class that is built into javascript?

 August 24, 2022     export, function, javascript, module, string     No comments   

Issue

I'm trying to export a function to use in another module, but it's one that I'm adding to the String javascript class.

How would I export the function to use in another module?

This is what I tried and it didn't work

String.prototype.trimChars = function(chars) {...}
export {String}

How do I make it so that this function is added to the string class as trimChars?


Solution

You can simply forgo the export, and import in another module. However, patching objects like this is not recommended, as it can introduce problems, if say, a browser adds a new function to String that happens to have the same name.

// in the other module
import "path/to/module.js";


Answered By - Allan J.
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing