简体   繁体   English

如何控制台记录JS对象的选项?

[英]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.

相关问题 如何在 Node js 中通过控制台日志显示选项列表并要求用户通过控制台日志从显示的列表中输入一个选项 - How is it possible in Node js to display list of options via console log and ask user to input a option from the displayed list via console log console.log() 对象不会记录通过节点 js 控制台中的原型添加的方法。 或者如何打印原型? - console.log() an object does not log the method added via prototype in node js console. Or how to print the prototypes also? 如何控制台对象内的日志对象 - How to console log object inside of an object 如何在 Node.js 的 console.log() 中获取完整的 object,而不是“[Object]”? - How can I get the full object in Node.js's console.log(), rather than '[Object]'? 为什么js变量显示[object object]但console.log()有效? - Why js variable show [object object] but console.log() works? Node.js console.log(object)打印空对象 - Node.js console.log(object) prints empty object 如何在 js 中 console.log 嵌套子数组? - How to console.log nested subarray in js? Ember.js —如何通过控制台记录模型 - Ember.js — how to console log a model 如何从 Chrome console.log() 输出中理解 JS 对象结构? - How to understand JS object structure from Chrome console.log() output? 如何在Node.js 11中控制台记录大对象 - How to console log big object in nodejs 11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM