简体   繁体   中英

How to console log an option of a JS object?

I would like to know how to console the value output of an option. In the example provided it would be the value of propOne, displayed here as 'value'. Thanks

var loadParallax = function(){
    $('.class-selector').parallax({
    propOne: 'value'
});

You need a reference to the passed in options object, then you can log it:

var options = {
    propOne: 'value'
};
var loadParallax = function(){
    $('.class-selector').parallax(options);
};

console.log(options.propOne); // => 'value'

For start, you should look into documentation for the plugin and search for something like getter, or options. Since you didn't state what plugin you use, I'll just give some tips, that could be useful.

Many plugins do this by method .option('name_of_option') or .get('name_of_option') or .method('get', 'name_of_option') so you can try for example loadParallax.get('name_of_option') . You can also try directly access the option as a property of object so you type loadParallax.name_of_option but many plugins disallows this.

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