Error:“Uncaught SyntaxError: Identifier 'Common' has already been declared after making javascript class object” in console?

0 votes
class Common
{
   constructor(){
    this.URL=location.protocol + '//' + location.host+'';
   }

    showOk(){
    console.log('ok');
    }

}
const commn=new Common();

Here is my html codes that I've tried to call the showOk() function.

<button type="button" class="btn btn-01 btn-checkout-login ml-auto w-100 text-center" onclick="return commn.showOk();" ;="">Continue Checkout</button>

<button type="button" class="btn btn-01 btn-checkout-login ml-auto w-100 text-center" onclick="commn.showOk();" ;="">Continue Checkout</button>
Apr 14 in Laravel by kartik
• 11,290 points
248 views

1 answer to this question.

0 votes

Hello,

You can write like this, you need know, class's instance's function is different with normal function.

<button onclick="handleClick();">click</button>

<script >

class Common {
   constructor(){
    this.URL=location.protocol + '//' + location.host+'';
   }

    showOk(){
     console.log('ok');
    }

}
const common = new Common();

function handleClick() {
  common.showOk();
}
</script>
answered Apr 14 by Niroj
• 22,790 points

Related Questions In Laravel

0 votes
1 answer

What are the important directories used in a common Laravel application

Hey @Kartik. Directories used in a common Laravel ...READ MORE

answered Mar 17 in Laravel by Niroj
• 22,790 points
34 views
0 votes
1 answer

Error:login in Laravel. How to solve?

Hey, First check if your model login has a field password in ...READ MORE

answered Mar 26 in Laravel by Niroj
• 22,790 points
86 views
0 votes
1 answer

Error:Composer Out of memory in Laravel?

Hey @kartik, This Error  happens in almost all ...READ MORE

answered Mar 30 in Laravel by Niroj
• 22,790 points
302 views
0 votes
1 answer

Error:My Routes are Returning a 404 in Laravel?

Hii @kartik Routes Use them to define specific routes ...READ MORE

answered Mar 30 in Laravel by Niroj
• 22,790 points
164 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 947 views
0 votes
0 answers
0 votes
1 answer

Error - 419 Sorry, your session has expired.Post request in Laravel?

Hello, case 1 : if you are running ...READ MORE

answered Mar 31 in Laravel by Niroj
• 22,790 points
1,130 views
0 votes
1 answer

Error:Class '\App\User' not found in Laravel when changing the namespace in Laravel?

Hello @kartik Go to config/auth.php and change App\User:class ...READ MORE

answered Apr 3 in Laravel by Niroj
• 22,790 points
414 views