eersteam eersteam - 1 month ago 12
React JSX Question

Calling function from a function in javascript es6

I'm using es6 javascript with babel and trying to make an ajax call using xhr using two function but getting an error

Uncaught TypeError: is not a function

What is the correct syntax to make a call to a function from another function defined in the same class in es6 javascript?

Thanks for your answer this is my code

import alt from '../../alt';
import cookie from 'react-cookie';

class LoginActions {
// Generic get request
post(url, data, callback) {
var xhr = new XMLHttpRequest();'POST', url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
callback(null, xhr.responseText);
} else {

// Get actual content
login(name, password, remember) {
var data = "name="+name+"&password="+password+"&remember="+remember;'api/login', data, function(err, data) {
if (!err) {
} else {


export default alt.createActions(LoginActions);

Edit1: This is how I call login function / also passed data to xhr request above


var name =;
var password = this.state.password;
var remember = this.state.remember;

LoginActions.login(name, password, remember);



Your methods login() and post() are instance methods, not static methods. So you have to create an instance of your LoginActions object with new in order to properly call those methods on that object.

Or if you don't actually need an instance with instance data, then make all the methods static and refer to them as and LoginActions.login(), not using this.

Instead, you're trying to mix and match. You're calling LoginActions.login() which is a static type call and then inside of login(), you're trying to reference this which assumes an instance.