undefined

How to assign string | undefined to string in TypeScript?

≡放荡痞女 提交于 2020-02-21 10:57:06
问题 I want to assign a variable, which is string | undefined, to a string variable, as you see here: private selectedSerialForReplace(): string | undefined { return this.selectedSerials.pop(); } luminaireReplaceLuminaire(params: { "serial": string; "newserial": string; }, options?: any): FetchArgs { ............ } luminaireReplaceLuminaire({serial: this.selectedSerialForReplace(), newserial: response.output}); I get this error: Argument of type '{ serial: string | undefined; newserial: any; }' is

js中void 0和undefined的区别

旧巷老猫 提交于 2020-02-20 11:43:45
http://blog.csdn.net/aitangyong/article/details/40309211 http://web.jobbole.com/86145/ 综合以上两个博客: 1.void其实是javascript中的一个函数,接受一个参数,返回值永远是undefined。可以说,使用void目的就是为了得到javascript中的undefined。So void 0 is a correct and standard way to produce undefined void 0 void (0) void "hello" void ( new Date()) //all will return undefined 2. 主要有2个原因: a、使用void 0比使用undefined能够减少3个字节。   >"undefined".length //9 >"void 0".length //6 b.undefined并不是javascript中的保留字,我们可以使用undefined作为变量名字,然后给它赋值。这样就会导致不一定会返回undefined,而void 0却永远可以保证。    (function(){     var undefined="haha";     alert(undefined); //"haha"    })() 3.额外篇: (

Undefined reference to vtable… Q_OBJECT macro [duplicate]

不打扰是莪最后的温柔 提交于 2020-02-16 06:23:26
问题 This question already has answers here : Qt Linker Error: “undefined reference to vtable” [duplicate] (9 answers) Closed 6 years ago . When I uncomment the Q_OBJECT macro that I need for signal-slot I get a undefined reference to vtable for MyApp error, but without the macro it compiles perfectly but I can't use signals and slots without it. I think I may be doing something stupid wrong, but please try helping because I realy can't find the problem. O and I know my code is untidy and am

Undefined reference to vtable… Q_OBJECT macro [duplicate]

拟墨画扇 提交于 2020-02-16 06:22:14
问题 This question already has answers here : Qt Linker Error: “undefined reference to vtable” [duplicate] (9 answers) Closed 6 years ago . When I uncomment the Q_OBJECT macro that I need for signal-slot I get a undefined reference to vtable for MyApp error, but without the macro it compiles perfectly but I can't use signals and slots without it. I think I may be doing something stupid wrong, but please try helping because I realy can't find the problem. O and I know my code is untidy and am

Transparency for specific values in matrix using Gnuplot while preserving the palette?

隐身守侯 提交于 2020-02-15 10:21:54
问题 Here's an interesting problem: I have a 2D "matrix" of double-precision, binary data I'd like to plot using Gnuplot. This is easily done as follows: plot "foo.dat" binary array=384x384 format='%double' with image The trick is that certain "regions" of the data have a special value, say 1234567890.0. I want those elements to be fully transparent, and all other matrix entires to be fully opaque. Is there a way to set the transparency channel based on the data itself? I have looked through the

Javascript中判断 Undefined 还是 Null 的方法

安稳与你 提交于 2020-02-11 14:28:09
在 JavaScript 中, null 用于对象, undefined 用于变量,属性和方法。 对象只有被定义才有可能为 null,否则为 undefined。 如果我们想测试对象是否存在,在对象还没定义时将会抛出一个错误。 错误的使用方式: if (myObj !== null && typeof myObj !== "undefined") 正确的方式是我们需要先使用 typeof 来检测对象是否已定义: if (typeof myObj !== "undefined" && myObj !== null) 出处: https://www.runoob.com/js/js-mistakes.html 来源: https://www.cnblogs.com/mq0036/p/12294765.html

JS高级技巧

。_饼干妹妹 提交于 2020-02-09 00:26:04
//region安全的类型检测 //可靠的方法:在任何值上调用原生toString()方法,都会返回一个[object NativeConstructorName]格式的字符串。每个类内部都有一个[Class]属性 这个属性指定了对应的构造函数名 var va = []; //alert( Object.prototype.toString.call( va ) );//[object Array] //endregion //region作用域安全的构造函数 function Person1( name, age ) { this.name = name; this.age = age; } var person1 = new Person1( "zodiac", 22 ); //每当使用new时 构造函数内的this对象会指向新创建的对象示例 //当没有使用new创建构造函数时出错 直接调用构造函数 this会映射到全局window对象 person1 = Person1( "zodiac", 22 ); // alert(window.name);//"zodiac" //解决方案: function Person2( name, age ) {//instanceof用来在运行时指出对象是否是特定类的一个实例 if ( this instanceof Person2 ) {

Ruby on Rails: undefined method `model_name' for NilClass:Class

你。 提交于 2020-02-07 03:35:32
问题 I am trying to allow a user to enter a project into a database. One of the fields allows them to enter multiple technologies for that project. Here is my project controller, new and create action. def new @project = Project.new @all_technols = Technol.all @project_technol = @project.projecttechnols.build respond_to do |format| format.html # new.html.erb format.json { render json: @project } end end def create @project = Project.new(params[:project]) params[:technols][:id].each do |technol| if

PHP Error: Undefined offset: 1

眉间皱痕 提交于 2020-02-01 05:15:49
问题 It seems like this might be an error dealing with arrays, but I can't figure it out. I'm really just starting with PHP and this is getting to be a little intimidating. Any help would be greatly appreciated! here is my code: <?php echo "<h1>Choose a Poll!</h1>"; $read = file('poll_topics.txt'); $data = array( ); foreach($read as $lines){ list($key,$v) = explode("|","$lines"); $data[$key] = $v; } foreach ($data as $k=>$desc){ echo "<ul><li><a href='take_a_poll.php?poll=$k'>$k</a> - $desc </li><

实现一个JSON.stringify()

牧云@^-^@ 提交于 2020-02-01 03:55:10
function jsonstringify(obj){   let type = typeof obj;   if(type !== 'object'){     if(/string|undefined|function/.test(type)){       obj = '"' + obj +'"'     }     return String(obj)   }else{     let arr = Array.isArray(obj);     let json =[];     for(let i in obj){       let j = obj[i];       let type = typeof j       if(/string|undefined|function/.test(type)){         j = '"' + j +'"'       }else if(type == 'object'){         j = jsonstringify(j)       }       json.push((arr ? "" : '"' + i + '":') + String(j));     }     return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}")   } }