问题标签 [object]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
asp.net - 如何在 asp.net 的对象数据源中动态更改连接字符串?
如何在 asp.net 的对象数据源中动态更改连接字符串?
javascript - Associative array without toString, etc
I want to create an associative array:
And I want to be sure that any key I access is going to be a number:
I know JavaScript doesn't have typing, so I can't automatically check this, but I can ensure in my own code that I only assign strings to this aa
.
Now I'm taking keys from the user. I want to display the value for that key. However, if the user gives me something like "toString", the user gets back a function, not an int! Is there a way to make sure any string the user gives me is only something I define?
Is the only solution something like the following?
etc...
delphi - Delphi(2006) 循环帮助
所以我基本上想要做的是让某件事在 70% 的时间发生,另外一些事情在每件事的 10% 的时间发生,如果这是有道理的,但我的应用程序似乎没有执行我猜测的任何操作我误解了循环语法或其他东西,无论如何,如果有人可以看一下,也许会给我一些建议
javascript - 为什么在 JavaScript 中函数既是构造函数又是对象?
我最近对此做了很多研究,但还没有得到一个很好的可靠答案。我在某处读到,当 JavaScript 引擎遇到一个函数语句时,会创建一个新的 Function() 对象,这让我相信它可能是一个对象的子对象(从而成为一个对象)。所以我给 Douglas Crockford 发了邮件,他的回答是:
不完全是,因为函数语句不调用编译器。
但它会产生类似的结果。
此外,据我所知,您不能在函数构造函数上调用成员,除非它已被实例化为新对象。所以这不起作用:
但是,这将起作用:
这只是语义问题吗……在整个编程世界中,对象何时真正成为对象,以及如何映射到 JavaScript?
ruby - 在 Ruby 中调用多个对象的方法的酷方法?
很久以前,我在 Ruby 中看到了这个技巧。而不是做(例如)
您可以一次调用所有对象并在最后附加操作,有点像
但我认为它比那更简单......或者,它可能就是那样。我真的不知道,但这就是为什么我有兴趣找出答案。谢谢。
javascript - JavaScript - check if in global context
When a function is attached to an object and called:
this
refers to the object that the function was called as a method of. It's equivalent to doing f.call(o)
.
When the function is called not as part of an object, this
refers to the global object. How do I check if a function is being called from a non-object context? Is there any standard keyword to access the global object? Is the only way to do it something like this?
Note: I have no particular use case in mind here - I actually am asking about this exact mechanism.
c++ - 无法分配作为指向模板化类的指针的成员
我的问题是,在我的“Widget”类中,我有以下声明:
在成员函数中,我以正常方式用地址初始化指针:
好的,最后一行使编译器停止在:
错误 C2166:左值指定 const 对象
好吧,为了简化事情,MouseEvent 被声明为 typedef:
正如您可能想象的那样,Event__2 是:(显示的基本结构):
我不知道 Event__2 类从哪里获得 const 限定符。有小费吗 ?
谢谢。
javascript - 如何检查 JavaScript 对象是否为 DOM 对象?
我试图得到:
在我自己的脚本中,我以前只是使用它,因为我不需要tagName
作为属性:
因此,对于第二个对象,我提出了以下作为快速解决方案的解决方案——这主要是可行的。;)
问题是,它取决于强制执行只读属性的浏览器,而并非所有浏览器都这样做。
有没有好的替代品?
javascript - JavaScript - 确定属性是否已定义并设置为“未定义”或未定义
假设我有以下代码:
o.x
并且t.x
都将评估为undefined
. o.hasOwnProperty('x')
并且t.hasOwnProperty('x')
都将返回false;也是如此propertyIsEnumerable
。两个问题:
- 有没有办法告诉 ox 已定义并设置为
undefined
? - 有任何理由吗?(两者在语义上应该是等价的吗?)
一个小警告:执行 (for propName in o) 循环将产生 'x' 作为字符串之一,而在 t 中执行不会 - 因此它们在内部的表示方式存在差异(至少在 Chrome 中)。
rest - REST 返回一个对象图
我是 REST 架构设计的新手,但我认为我已经掌握了它的基础知识。
我从 RESTful 调用返回对象时遇到问题。如果我发出诸如http://localhost/ {type A}/{id} 之类的请求,我将从数据库中返回一个具有指定 ID 的 A 实例。
我的问题是当 A 包含 B 对象的集合时会发生什么?目前,我生成的 XML 返回 A,其中包含 B 对象的集合。可以想象,如果 B 类型有一个 C 对象的集合,那么返回的 XML 最终将是一个相当复杂的对象图。
我不能 100% 确定,但这感觉违反了 RESTful 原则,A 的 XML 应该将 A 的字段等以及 URI 的集合返回到它拥有的 B 的集合。
抱歉,如果这有点令人困惑,我可以尝试详细说明。这似乎是一个相对基本的问题,但是我无法确定哪种方法“更”RESTful。
干杯,
艾多斯