[英]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'. 在提供的示例中,该值为propOne的值,此处显示为“值”。 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. 首先,您应该查看插件的文档并搜索诸如getter或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')
. 许多插件通过方法.option('name_of_option')
或.get('name_of_option')
或.method('get', 'name_of_option')
因此您可以尝试例如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. 您也可以尝试直接将选项作为对象的属性来访问,因此您键入loadParallax.name_of_option
但是许多插件都不允许这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.