简体   繁体   中英

How to define a javascript function from Chromium Console

I'm trying to define a Javascript function or a simple variable in Chromium Browser debugger console. After definition, when I cannot reach this function. What shall be the problem for it?

Here are the variable and function definition that I write on the chromium console:

var myvar;

var f = function(){
   console.log("Hello world");
};

function f2(){
   console.log("Hello world");
};

By the way, I can reach the functions that I created at Mozilla Firefox Browser.

What is the problem with Chromium Browser?

function is reserved word in javascript.

Try this

var f = function() {
   console.log("Hello world");
};

instead of

var function = f(){
   console.log("Hello world");
};

You can try this:

function fun(a,b)
{
   console.log(a,b);
}

fun(5,6); // calling

You can also write

document.myFunc = function(){alert("Hello");}

Call it with

document.myFunc()

But I'm not an expert

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM