undefined

How can I distinguish between an argument that was not passed and one that was passed with a false value?

倾然丶 夕夏残阳落幕 提交于 2019-12-22 04:37:06
问题 I am trying to figure the best way to differeniate in Perl between cases where an argument has not been passed, and where an argument has been passed as 0, since they mean different things to me. (Normally I like the ambiguity, but in this case I'm generating SQL so I want to replace undefined args with NULL, but leave 0 as 0.) So this is the ambiguity: sub mysub { my $arg1 = shift; if ($arg1){ print "arg1 could have been 0 or it could have not been passed."; } } And so far, this is my best

Is there a way to handle undefined functions being called in JavaScript?

拟墨画扇 提交于 2019-12-22 04:36:11
问题 If I have a function like the following: function catchUndefinedFunctionCall( name, arguments ) { alert( name + ' is not defined' ); } and I do something silly like foo( 'bar' ); when foo isn't defined, is there some way I can have my catch function called, with name being 'foo' and arguments being an array containing 'bar'? 回答1: There is in Mozilla Javascript 1.5 anyway (it's nonstandard). Check this out: var myObj = { foo: function () { alert('foo!'); } , __noSuchMethod__: function (id,

Undefined method “has_attached_file” for my ActiveRecord model

瘦欲@ 提交于 2019-12-22 01:01:40
问题 I followed the docs at https://github.com/thoughtbot/paperclip exactly to install implement paperclip in my app for image uploading. I am currently using gem 'paperclip', '~> 5.0.0.beta1'. After I did the migration, the four columns were added onto my schema properly: t.string "picture_file_name" t.string "picture_content_type" t.integer "picture_file_size" t.datetime "picture_updated_at" My paperclip should therefore be installed correctly. However, when I proceeded to add the following two

TypeScript Decorators and Circular Dependencies

假如想象 提交于 2019-12-21 20:19:35
问题 Consider the sample of inter-dependent code (below) that makes use of decorators. Now consider the following workflow (yes, I do want to pass the actual exported classes since I need to use them later): App imports and runs Parent.ts @Test(Child) causes the app to import Child.ts while decorating Note: the class Parent has not yet been reached by the code In Child.ts , the @Test(Parent) decorator is executed At this point, Parent is undefined and cannot be passed to the decorator. As you see,

How do you implement a guard clause in JavaScript?

一曲冷凌霜 提交于 2019-12-21 09:36:18
问题 I want to guard my functions against null-ish values and only continue if there is "defined" value. After looking around the solutions suggested to double equal to undefined: if (something == undefined) . The problem with this solution is that you can declare an undefined variable. So my current solution is to check for null if(something == null) which implicetly checks for undefined. And if I want to catch addionalty falsy values I check if(something) . See tests here: http://jsfiddle.net

Why is localStorage[“…”] undefined, but localStorage.getItem(“…”) is null?

五迷三道 提交于 2019-12-21 09:16:21
问题 Last time I checked, the following two lines returned true : null == localStorage["foo"]; null == localStorage.getItem("foo"); Same applies when replacing null with undefined . So the first question is, why are there two ways to address the localStorage? And why does localStorage["foo"] return undefined while localStorage.getItem("foo") returns null ? Do I need to take care of that when developing JS? 回答1: The Web Storage Specification requires that .getItem() returns null for an unknown key.

jasmine unit testing - testing for an undefined property of an object

无人久伴 提交于 2019-12-21 06:48:08
问题 I have the following statement expect(A.["BAR"].name).toEqual("foo"); which due to the fact my object A has the top level property "BAR" and bar has the value "foo" passes. I'd like to test my structure to confirm a property "NONEXISTINGPROP" has not be defined. e.g. expect(A.["NONEXISTINGPROP"].name).not.toBeDefined(); However I seem to get "TypeError: A.[NONEXISTINGPROP] is undefined" in the jasmine test runner this is exactly what I want to confirm. Any idea why Jasmine is crying. I was

What is faster? Running an empty function or checking if function is undefined? [closed]

半世苍凉 提交于 2019-12-21 04:21:15
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I was writing some code where a function being passed in as an argument might sometimes be undefined. Being curious about this as bad 'practice', I wondered what is actually faster? Giving an empty function, or having the function check if the argument was undefined? I did

Undefined method 'map' for nil:NilClass

这一生的挚爱 提交于 2019-12-21 04:20:45
问题 My app seems to randomly be throwing a "undefined method `map' for nil:NilClass" error when users are trying to update their profile. But what's weird is it's saying the error happens on update, but the error line is actually in a view. Full error: users#update (ActionView::TemplateError) "undefined method `map' for nil:NilClass" On line #52 of app/views/users/edit.html.erb Line 52: <%= options_from_collection_for_select(@networks_domestic, 'id', 'name', @user.network_id) %> And here are the

jQuery val is undefined?

99封情书 提交于 2019-12-21 03:41:26
问题 I have this code: <input type="hidden" id="editorTitle" name="title" value="home"> <textarea name="text" id="editorText"></textarea> But when i write $('#editorTitle').val() and $('#editorText').html() , $('#editorTitle').val() is 'undefined' and $('#editorText').html() is empty? What is wrong? Edit: Here is my full code: function openEditor() { $("#editor").show().animate({ width: 965, height: 380 }, 1500); $("#editor textarea").show(); } function closeEditor() { $("#editor").animate({ width