我想编写一个 Javascript 库,并且希望用户仅在其 HTML 页面中导入该库的主文件。然而,我发现如果我使用类似的技巧
function dynamicallyLoadScript(url) {
var script = document.createElement("script"); // create a script DOM node
script.src = url; // set its src to the provided URL
document.head.appendChild(script); // add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead)
}
Run Code Online (Sandbox Code Playgroud)
要包含的脚本的路径必须从 HTML 文件开始计算,这意味着用户必须将文件放在特定位置才能使其工作。
我想知道是否值得重写这些文件以包含为 ES6 模块。这样做会使脚本的路径相对于包含它的 Javascript 文件吗?如果没有,大型图书馆如何处理这个问题?
只是为了看看我对++c
/c++
运算符的工作原理了解多少,我尝试运行这些 C 程序:
int c = 5;
c = c - c++;
printf("%d\n", c);
Run Code Online (Sandbox Code Playgroud)
打印 1,我猜逻辑是 ++ 在使用它的代码行之后应用,因此c
变为= c - c
0,并在“下一行”增加一。但对我来说似乎很奇怪,我想更详细地了解操作员优先级应该发生什么。
现在开始:
int c = 5;
c = c - ++c;
printf("%d\n", c);
Run Code Online (Sandbox Code Playgroud)
这个打印0,我真的不明白为什么。如果从左到右解析右手值,我想它会读取c
哪个是 5,然后++c
哪个是 6,因为它应该立即应用。或者它是否++c
在整个右手值计算之前计算,因此它实际上是在做 6 - 6,因为增量还涉及第一次调用c
?
在尝试找到一种在 JS 中使用嵌套类的方法时,我想到了这样的事情:
class Character {
constructor() {
this.Info= class I {
constructor(name,value) {
this.name=name;
this.value=value;
}
};
}
bar () {
var trial = new this.Info("Goofy", 2);
alert(trial.name);
}
}
var test = new Character();
test.bar();
Run Code Online (Sandbox Code Playgroud)
这似乎有效。但是,我担心这可能会为每次调用创建一个新的函数对象new
,因为我在构造函数中定义了该类(在每次new
调用时执行)。有没有更有效的方法来做到这一点?
这个问题并没有解决我的问题,因为作者只是想知道如何嵌套class
; 我已经能够做到这一点,但我想知道是否有更有效的方法。
在我的着色器中,我喜欢使用这样的语法:
layout (location = 0) in vec3 aPos;
所以,我可以只使用索引0
中glVertexAttribPointer
和这样的,节省了努力glGetAttribLocation
通话。我想对uniform
价值观做同样的事情,但如果我这样做
layout (location = 2) uniform float offset;
Run Code Online (Sandbox Code Playgroud)
我的顶点着色器无法编译。有没有办法实现相同的行为而不使用glGetUniformLocation
?
c++ ×2
javascript ×2
c ×1
class ×1
es6-modules ×1
github-pages ×1
glsl ×1
jekyll ×1
object ×1
oop ×1
opengl ×1
opengl-3 ×1
opengl-4 ×1