这听起来像是一个微不足道的问题,但我似乎无法从谷歌找到明确的答案。
我已经阅读了有关 SDK 和库的文章。我对两者都有基本的了解。根据我的阅读,我总结了 SDK 和 Library 如下:
图书馆:
Library is a chunk of codes that allows devs to perform certain action for specific task.
SDK:
While SDK is an interface, usually functions that allows the devs to interact with the library. It can also be groups of libraries for certain task
对于库,根据我的经验,它不是跨JS库的。例如,react 库可能无法在纯 javascipt 库中使用。
但是,既然SDK更像是一个接口(interface),那么是否意味着SDK是跨JS库的?
这意味着,如果我实现了一个 React SDK,它可以在纯 JavaScript 中使用吗?反之亦然?
最佳答案
这在技术上是可行的,是的。您只需从某些 CDN 导入库即可使用它们:
<script src="https://unpkg.com/react@15/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>
但是,这确实不推荐,因为您将无法使用 React 拥有的许多强大功能,而这些功能在使用构建系统(即 Webpack)和转译器(即 Babel)时会获得。例如:
您将无法使用 JSX 语法,因此:
return (
<h1>Greetings, {this.props.name}!</h1>
);
会变成:
return React.createElement('h1', null, 'Greetings, ' + this.props.name + '!');
而且你也无法使用大多数 React 项目中广泛使用的 ES6 功能,例如箭头函数、Promise 等。
关于javascript - React SDK可以在纯JavaScript中使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54007765/