我一直在阅读了关于克罗克福德的垫片,以防止原型的改写,并了解它的不是结束,所有的/是的解决办法的时候.我也明白,ES5 Shim可能是一个可行的替代品.我还阅读了这篇文章,它提供了一个更强大,更安全的选择.
不过,我想知道他的Object.create
垫片是什么"说"然后"做".如果我的解释评论是正确的,有人可以告诉我吗?
if (typeof Object.create === 'undefined') {
//If the browser doesn't support Object.create
Object.create = function (o) {
//Object.create equals an anonymous function that accepts one parameter, 'o'.
function F() {};
//Create a new function called 'F' which is just an empty object.
F.prototype = o;
//the prototype of the 'F' function should point to the
//parameter of the anonymous function.
return new F();
//create a new constructor function based off of …
Run Code Online (Sandbox Code Playgroud) 我正在为以下名为"test.css"的css文件设置grunt缩小任务:
body{
background-color: #fff;
text-align: left;
}
Run Code Online (Sandbox Code Playgroud)
我跑的时候收到以下消息grunt
:
WARN: ERROR: Unexpected token: punc ({) [test.css:1,4]
我的"Gruntfile.js"文件当前看起来像这样:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
min: {
src: 'test.css',
dest: 'test.min.css'
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('default', ['uglify']);
};
Run Code Online (Sandbox Code Playgroud)
我的"package.json"文件目前看起来像这样:
{
"name": "kaidez",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.0",
"grunt-contrib-uglify": "~0.1.1"
}
}
Run Code Online (Sandbox Code Playgroud)
运行grunt v4.0和node v0.8.20,两者都是全局安装的.这两个grunt-cli
和uglify
安装."Gruntfile.js","package.json"和"test.css"位于同一目录中.所有这些文件都在WordPress网站的"主题"目录中,但我不是那个问题.
有任何想法吗?
在 React 中,基于文档 [here][1],我试图选择一个 AG Grid 行以使用以下代码删除:
class MyComponent extends Component {
constructor(props) {
this.state={rowSelection: 'single'}
}
onGridReady(params) {
this.gridApi = params.api
this.columnApi = params.columnApi
}
onRemoveSelected() {
const selectedData = this.gridApi.getSelectedRows();
const res = this.gridApi.updateRowData({ remove: selectedData })
}
}
render() {
return(
<div>
<button onClick={this.onRemoveSelected.bind(this)}>Remove Selected</button>
<AgGridReact
id="myGrid"
{...gridOptions}
onGridReady={this.onGridReady}
rowSelection={this.state.rowSelection}
/>
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
但该行没有选择。此外,使用不同的代码变体,有时我会收到此控制台警告:
cannot select node until id for node is known
Run Code Online (Sandbox Code Playgroud)
提前致谢 [1]:https : //www.ag-grid.com/javascript-grid-data-update/
聚合物noob ...
我正在尝试根据Polymer API文档创建自定义元素,其中我的主页面如下所示:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Polymer</title>
<script src="bower_components/platform/platform.js"></script>
<link rel="import" href="bower_components/polymer/polymer.html">
</head>
<body>
<div id="test"></div>
<polymer-element name="book-template" constructor="BookTemplate" noscript>
<template>
<style>
h1 { color: orange; }
</style>
<h1>Hello from some-foo</h1>
</template>
</polymer-element>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我知道如果我只是放在<book-template></book-template>
页面上,或者如果我在<body>
标签内做了类似的事情,页面内容将呈现:
<script>
var book = document.createElement('book-template');
document.getElementById('test').appendChild(book);
</script>
Run Code Online (Sandbox Code Playgroud)
但我正在尝试使用元素的构造函数属性,假设这将在放置在其中的某个位置时创建元素<body>
:
<script>
var book = new BookTemplate();
</script>
Run Code Online (Sandbox Code Playgroud)
...但获取未定义BookTemplate()的控制台消息.
我确定这很简单......任何想法?提前致谢.
在阅读道格拉斯·克罗克福德的"JavaScript:The Good Parts"和Stoyan Stevanov的"JavaScript模式"之后,我试图确定"过度棘手"的含义.他们都说这在使用任何一个++
或--
在您的代码中时都会出现,但无法在SO中或通过Google搜索找到该术语的固定定义.有任何想法吗?
我正在尝试设置grunt-contrib-sass,以便我可以使用grunt来处理sass-to-css编译.我在脚手架上安装了一个基本的grunt文件grunt init:makefile
.当我跑来grunt sass
测试时,终端返回"没有"sass"找到的目标".
我的设置:
$ sass -v返回"Sass 3.2.1"
$ ruby -v返回"ruby 1.9.3p194"
'node_modules'文件夹包含'grunt-contrib-sass'
基于grunt-contrib-sass文档,我的grunt.js文件目前看起来像这样:
module.exports = function(grunt) {
grunt.initConfig({
lint: {
files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js']
},
test: {
files: ['test/**/*.js']
},
watch: {
files: '<config:lint.files>',
tasks: 'lint test'
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true
},
globals: {},
sass: { // Task
dist: { // Target
files: { …
Run Code Online (Sandbox Code Playgroud)