简体   繁体   English

在JavaScript中声明式编码的幕后是否仍然势在必行?

[英]Is behind the hood of declarative coding is still imperative in Javascript?

I read the difference of imperative and declarative paradigms here 我在这里阅读了命令式和声明式范式的区别

https://codeburst.io/declarative-vs-imperative-programming-a8a7c93d9ad2 https://codeburst.io/declarative-vs-imperative-programming-a8a7c93d9ad2

The author then use React and JQuery as examples, but then under all the cool stuffs that React use, it must have been normal Javascript which must be imperative,isnt it? 然后,作者以React和JQuery为例,但是在React使用的所有有趣的东西下,它一定是普通的Javascript,必须使用它,不是吗? (Do this then do that, etc. ...) (先执行此操作,再执行其他操作……)

There are languages that said to be declarative by nature (SQL), am I correct to say that Javascript is imperative by nature, but can be declarative then? 有些语言据说是本质上的声明式(SQL),我是否正确地说Javascript本质上是命令性的,但是可以声明性吗?

I can only really speak about jQuery here since I never worked with React before. 因为我以前从未使用过React,所以我只能在这里真正谈论jQuery。

jQuery is written in JavaScript and as such is imperative "under the hood". jQuery用JavaScript编写,因此势在必行。 It simply gives you the option to write more or less declarative code by having a bunch of predefined functions. 它只是提供了一系列预定义函数,使您可以选择编写或多或少的声明性代码。 If you think about it this way, pretty much everything is imperative "under the hood" though because, once compiled, everything is broken into simple imperative instructions. 如果您以这种方式考虑,那么几乎所有内容都是“幕后”的命令性内容,因为一旦编译后,所有内容都会分解为简单的命令性指令。

In most cases the technology behind what you are using will not matter to you. 在大多数情况下,您所使用的背后的技术对您而言并不重要。 So while you are using a declarative framework on top of a imperative language, you are still writing declarative code. 因此,当您在命令性语言之上使用声明性框架时,仍在编写声明性代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM